vet: go fix -inline (Go 1.27 prep)

This commit is contained in:
Jordan Liggitt committed 2026-09-03 18:08:38 -04:00
1 parent 504a667822
commit b43e5e6a7a
20 files changed
+58 -62

No files matched your search

+2 -3
View File
@@ -18,7 +18,6 @@ package abac
import (
"context"
"io/ioutil"
"os"
"reflect"
"testing"
@@ -818,14 +817,14 @@ func TestSubjectMatches(t *testing.T) {
}
func newWithContents(t *testing.T, contents string) (PolicyList, error) {
f, err := ioutil.TempFile("", "abac_test")
f, err := os.CreateTemp("", "abac_test")
if err != nil {
t.Fatalf("unexpected error creating policyfile: %v", err)
}
f.Close()
defer os.Remove(f.Name())
if err := ioutil.WriteFile(f.Name(), []byte(contents), 0700); err != nil {
if err := os.WriteFile(f.Name(), []byte(contents), 0700); err != nil {
t.Fatalf("unexpected error writing policyfile: %v", err)
}
@@ -24,7 +24,8 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"math/rand"
"reflect"
"testing"
@@ -88,7 +89,7 @@ func TestSigner(t *testing.T) {
t.Fatalf("failed to create signer: %v", err)
}
csrb, err := ioutil.ReadFile("./testdata/kubelet.csr")
csrb, err := os.ReadFile("./testdata/kubelet.csr")
if err != nil {
t.Fatalf("failed to read CSR: %v", err)
}
+1 -1
View File
@@ -542,7 +542,7 @@ func TestGenericStorageProviders(t *testing.T) {
}
// special case: we identify full core and generic core
if kt.Kind() == reflect.Ptr && kt.Elem().PkgPath() == reflect.TypeOf(corerest.Config{}).PkgPath() {
if kt.Kind() == reflect.Pointer && kt.Elem().PkgPath() == reflect.TypeOf(corerest.Config{}).PkgPath() {
kt = reflect.TypeOf(&corerest.GenericConfig{})
}
View File
Whitespace-only changes.
+2 -2
View File
@@ -435,7 +435,7 @@ func TestMakePayload(t *testing.T) {
}
func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.VolumeHost) {
tempDir, err := ioutil.TempDir("", "configmap_volume_test.")
tempDir, err := os.MkdirTemp("", "configmap_volume_test.")
if err != nil {
t.Fatalf("can't make a temp rootdir: %v", err)
}
@@ -846,7 +846,7 @@ func doTestConfigMapDataInVolume(volumePath string, configMap v1.ConfigMap, t *t
if _, err := os.Stat(configMapDataHostPath); err != nil {
t.Fatalf("SetUp() failed, couldn't find configMap data on disk: %v", configMapDataHostPath)
} else {
actualValue, err := ioutil.ReadFile(configMapDataHostPath)
actualValue, err := os.ReadFile(configMapDataHostPath)
if err != nil {
t.Fatalf("Couldn't read configMap data from: %v", configMapDataHostPath)
}
+2 -2
View File
@@ -18,7 +18,7 @@ package git_repo
import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -41,7 +41,7 @@ import (
)
func newTestHost(t *testing.T) (string, volume.VolumeHost) {
tempDir, err := ioutil.TempDir("", "git_repo_test.")
tempDir, err := os.MkdirTemp("", "git_repo_test.")
if err != nil {
t.Fatalf("can't make a temp rootdir: %v", err)
}
+1 -2
View File
@@ -19,7 +19,6 @@ limitations under the License.
package iscsi
import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -441,7 +440,7 @@ func TestGetVolCount(t *testing.T) {
}
func createFakePluginDirs() (string, error) {
dir, err := ioutil.TempDir("", "refcounter")
dir, err := os.MkdirTemp("", "refcounter")
if err != nil {
return "", err
}
+2 -2
View File
@@ -398,7 +398,7 @@ func TestMakePayload(t *testing.T) {
}
func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.VolumeHost) {
tempDir, err := ioutil.TempDir("", "secret_volume_test.")
tempDir, err := os.MkdirTemp("", "secret_volume_test.")
if err != nil {
t.Fatalf("can't make a temp rootdir: %v", err)
}
@@ -805,7 +805,7 @@ func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T)
if _, err := os.Stat(secretDataHostPath); err != nil {
t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath)
} else {
actualSecretBytes, err := ioutil.ReadFile(secretDataHostPath)
actualSecretBytes, err := os.ReadFile(secretDataHostPath)
if err != nil {
t.Fatalf("Couldn't read secret data from: %v", secretDataHostPath)
}
+20 -20
View File
@@ -203,7 +203,7 @@ func TestSafeMakeDir(t *testing.T) {
{
"non-directory",
func(base string) error {
return ioutil.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
return os.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
},
"test/directory",
"",
@@ -213,7 +213,7 @@ func TestSafeMakeDir(t *testing.T) {
{
"non-directory-final",
func(base string) error {
return ioutil.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
return os.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
},
"test",
"",
@@ -264,7 +264,7 @@ func TestSafeMakeDir(t *testing.T) {
for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
base, err := os.MkdirTemp("", "safe-make-dir-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -374,7 +374,7 @@ func TestRemoveEmptyDirs(t *testing.T) {
if err := os.MkdirAll(filepath.Join(base, "a/b"), defaultPerm); err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(base, "a/b", "c"), []byte{}, defaultPerm)
return os.WriteFile(filepath.Join(base, "a/b", "c"), []byte{}, defaultPerm)
},
validate: func(base string) error {
if err := validateDirExists(filepath.Join(base, "a/b")); err != nil {
@@ -390,7 +390,7 @@ func TestRemoveEmptyDirs(t *testing.T) {
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
base, err := ioutil.TempDir("", "remove-empty-dirs-"+test.name+"-")
base, err := os.MkdirTemp("", "remove-empty-dirs-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -456,7 +456,7 @@ func TestCleanSubPaths(t *testing.T) {
if err := os.MkdirAll(path, defaultPerm); err != nil {
return nil, err
}
return nil, ioutil.WriteFile(filepath.Join(path, "0"), []byte{}, defaultPerm)
return nil, os.WriteFile(filepath.Join(path, "0"), []byte{}, defaultPerm)
},
validate: func(base string) error {
return validateDirNotExists(filepath.Join(base, containerSubPathDirectoryName))
@@ -470,7 +470,7 @@ func TestCleanSubPaths(t *testing.T) {
if err := os.MkdirAll(path, defaultPerm); err != nil {
return nil, err
}
return nil, ioutil.WriteFile(filepath.Join(path, "container1"), []byte{}, defaultPerm)
return nil, os.WriteFile(filepath.Join(path, "container1"), []byte{}, defaultPerm)
},
validate: func(base string) error {
return validateDirExists(filepath.Join(base, containerSubPathDirectoryName, testVol))
@@ -484,7 +484,7 @@ func TestCleanSubPaths(t *testing.T) {
if err := os.MkdirAll(filepath.Join(path, "container1"), defaultPerm); err != nil {
return nil, err
}
return nil, ioutil.WriteFile(filepath.Join(path, "container2"), []byte{}, defaultPerm)
return nil, os.WriteFile(filepath.Join(path, "container2"), []byte{}, defaultPerm)
},
validate: func(base string) error {
path := filepath.Join(base, containerSubPathDirectoryName, testVol)
@@ -567,7 +567,7 @@ func TestCleanSubPaths(t *testing.T) {
}
file0 := filepath.Join(containerPath, "0")
if err := ioutil.WriteFile(file0, []byte{}, defaultPerm); err != nil {
if err := os.WriteFile(file0, []byte{}, defaultPerm); err != nil {
return nil, err
}
@@ -582,7 +582,7 @@ func TestCleanSubPaths(t *testing.T) {
}
file3 := filepath.Join(containerPath, "3")
if err := ioutil.WriteFile(file3, []byte{}, defaultPerm); err != nil {
if err := os.WriteFile(file3, []byte{}, defaultPerm); err != nil {
return nil, err
}
@@ -620,7 +620,7 @@ func TestCleanSubPaths(t *testing.T) {
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
base, err := ioutil.TempDir("", "clean-subpaths-"+test.name+"-")
base, err := os.MkdirTemp("", "clean-subpaths-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -708,7 +708,7 @@ func TestBindSubPath(t *testing.T) {
if err := os.MkdirAll(volpath, defaultPerm); err != nil {
return nil, "", "", err
}
return nil, volpath, subpath, ioutil.WriteFile(subpath, []byte{}, defaultPerm)
return nil, volpath, subpath, os.WriteFile(subpath, []byte{}, defaultPerm)
},
expectError: false,
},
@@ -757,7 +757,7 @@ func TestBindSubPath(t *testing.T) {
return nil, "", "", err
}
// touch file outside
if err := ioutil.WriteFile(child, []byte{}, defaultPerm); err != nil {
if err := os.WriteFile(child, []byte{}, defaultPerm); err != nil {
return nil, "", "", err
}
@@ -792,7 +792,7 @@ func TestBindSubPath(t *testing.T) {
return nil, "", "", err
}
// touch file outside
if err := ioutil.WriteFile(child, []byte{}, defaultPerm); err != nil {
if err := os.WriteFile(child, []byte{}, defaultPerm); err != nil {
return nil, "", "", err
}
@@ -881,7 +881,7 @@ func TestBindSubPath(t *testing.T) {
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
base, err := ioutil.TempDir("", "bind-subpath-"+test.name+"-")
base, err := os.MkdirTemp("", "bind-subpath-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -1050,7 +1050,7 @@ func TestSubpath_PrepareSafeSubpath(t *testing.T) {
}
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
base, err := ioutil.TempDir("", "bind-subpath-"+test.name+"-")
base, err := os.MkdirTemp("", "bind-subpath-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -1372,7 +1372,7 @@ func TestSafeOpen(t *testing.T) {
{
"non-directory",
func(base string) error {
return ioutil.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
return os.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
},
"test/directory",
true,
@@ -1380,7 +1380,7 @@ func TestSafeOpen(t *testing.T) {
{
"non-directory-final",
func(base string) error {
return ioutil.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
return os.WriteFile(filepath.Join(base, "test"), []byte{}, defaultPerm)
},
"test",
false,
@@ -1448,7 +1448,7 @@ func TestSafeOpen(t *testing.T) {
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
base, err := ioutil.TempDir("", "safe-open-"+test.name+"-")
base, err := os.MkdirTemp("", "safe-open-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -1595,7 +1595,7 @@ func TestFindExistingPrefix(t *testing.T) {
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
base, err := ioutil.TempDir("", "find-prefix-"+test.name+"-")
base, err := os.MkdirTemp("", "find-prefix-"+test.name+"-")
if err != nil {
t.Fatal(err.Error())
}
@@ -20,7 +20,6 @@ package subpath
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -37,7 +36,7 @@ func makeLink(link, target string) error {
}
func TestDoSafeMakeDir(t *testing.T) {
base, err := ioutil.TempDir("", "TestDoSafeMakeDir")
base, err := os.MkdirTemp("", "TestDoSafeMakeDir")
if err != nil {
t.Fatalf("failed to create temporary directory: %v", err)
}
@@ -133,7 +132,7 @@ func TestDoSafeMakeDir(t *testing.T) {
}
func TestLockAndCheckSubPath(t *testing.T) {
base, err := ioutil.TempDir("", "TestLockAndCheckSubPath")
base, err := os.MkdirTemp("", "TestLockAndCheckSubPath")
if err != nil {
t.Fatalf("failed to create temporary directory: %v", err)
}
@@ -237,7 +236,7 @@ func TestLockAndCheckSubPath(t *testing.T) {
}
func TestLockAndCheckSubPathWithoutSymlink(t *testing.T) {
base, err := ioutil.TempDir("", "TestLockAndCheckSubPathWithoutSymlink")
base, err := os.MkdirTemp("", "TestLockAndCheckSubPathWithoutSymlink")
if err != nil {
t.Fatalf("failed to create temporary directory: %v", err)
}
@@ -341,7 +340,7 @@ func TestLockAndCheckSubPathWithoutSymlink(t *testing.T) {
}
func TestFindExistingPrefix(t *testing.T) {
base, err := ioutil.TempDir("", "TestFindExistingPrefix")
base, err := os.MkdirTemp("", "TestFindExistingPrefix")
if err != nil {
t.Fatalf("failed to create temporary directory: %v", err)
}
@@ -19,7 +19,6 @@ package roundtrip
import (
"bytes"
gojson "encoding/json"
"io/ioutil"
"net/http"
"os"
"os/exec"
@@ -334,11 +333,11 @@ func (c *CompatibilityTestOptions) encode(t *testing.T, obj runtime.Object) (jso
func read(dir string, gvk schema.GroupVersionKind, suffix string, usedFiles sets.String) (json, yaml, proto []byte, err error) {
jsonFilename := makeName(gvk) + suffix + ".json"
actualJSON, jsonErr := ioutil.ReadFile(filepath.Join(dir, jsonFilename))
actualJSON, jsonErr := os.ReadFile(filepath.Join(dir, jsonFilename))
yamlFilename := makeName(gvk) + suffix + ".yaml"
actualYAML, yamlErr := ioutil.ReadFile(filepath.Join(dir, yamlFilename))
actualYAML, yamlErr := os.ReadFile(filepath.Join(dir, yamlFilename))
protoFilename := makeName(gvk) + suffix + ".pb"
actualProto, protoErr := ioutil.ReadFile(filepath.Join(dir, protoFilename))
actualProto, protoErr := os.ReadFile(filepath.Join(dir, protoFilename))
if usedFiles != nil {
usedFiles.Insert(jsonFilename)
usedFiles.Insert(yamlFilename)
@@ -360,7 +359,7 @@ func writeFile(t *testing.T, dir string, gvk schema.GroupVersionKind, suffix, ex
if err := os.MkdirAll(dir, os.FileMode(0755)); err != nil {
t.Fatal("error making directory", err)
}
if err := ioutil.WriteFile(filepath.Join(dir, makeName(gvk)+suffix+"."+extension), data, os.FileMode(0644)); err != nil {
if err := os.WriteFile(filepath.Join(dir, makeName(gvk)+suffix+"."+extension), data, os.FileMode(0644)); err != nil {
t.Fatalf("error writing %s: %v", extension, err)
}
}
@@ -19,7 +19,7 @@ package streaming
import (
"bytes"
"io"
"io/ioutil"
"testing"
"k8s.io/apimachinery/pkg/runtime"
@@ -41,7 +41,7 @@ func (d *fakeDecoder) Decode(data []byte, gvk *schema.GroupVersionKind, into run
func TestEmptyDecoder(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
d := &fakeDecoder{}
_, _, err := NewDecoder(ioutil.NopCloser(buf), d).Decode(nil, nil)
_, _, err := NewDecoder(io.NopCloser(buf), d).Decode(nil, nil)
if err != io.EOF {
t.Fatal(err)
}
@@ -199,7 +199,7 @@ func (e Equalities) deepValueEqual(v1, v2 reflect.Value, visited map[visit]bool,
return v1.IsNil() == v2.IsNil()
}
return e.deepValueEqual(v1.Elem(), v2.Elem(), visited, equateNilAndEmpty, depth+1)
case reflect.Ptr:
case reflect.Pointer:
return e.deepValueEqual(v1.Elem(), v2.Elem(), visited, equateNilAndEmpty, depth+1)
case reflect.Struct:
for i, n := 0, v1.NumField(); i < n; i++ {
@@ -202,7 +202,7 @@ func redactSecrets(curr reflect.Value, redact bool) error {
}
actualCurrValue := curr
if curr.Kind() == reflect.Ptr {
if curr.Kind() == reflect.Pointer {
actualCurrValue = curr.Elem()
}
@@ -28,7 +28,7 @@ func ReflectDeepCopy(in interface{}) interface{} {
func reflectDeepCopy(src reflect.Value) reflect.Value {
switch src.Kind() {
case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
case reflect.Interface, reflect.Pointer, reflect.Map, reflect.Slice:
if src.IsNil() {
return src
}
@@ -51,7 +51,7 @@ func reflectDeepCopy(src reflect.Value) reflect.Value {
dst.SetMapIndex(k, reflectDeepCopy(src.MapIndex(k)))
}
return dst
case reflect.Ptr:
case reflect.Pointer:
dst := reflect.New(src.Type().Elem())
dst.Elem().Set(reflectDeepCopy(src.Elem()))
return dst
@@ -40,7 +40,7 @@ func valueFuzz(obj reflect.Value) {
valueFuzz(obj.Index(i))
}
}
case reflect.Interface, reflect.Ptr:
case reflect.Interface, reflect.Pointer:
if obj.IsNil() {
// TODO: set non-nil value
} else {
@@ -131,12 +131,12 @@ func (s *ValidationTestBuilder) ValidateFixtures() {
for t := range s.s.validationFuncs {
var v any
// TODO: this should handle maps and slices
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
v = reflect.New(t.Elem()).Interface()
} else {
v = reflect.Indirect(reflect.New(t)).Interface()
}
if reflect.TypeOf(v).Kind() != reflect.Ptr {
if reflect.TypeOf(v).Kind() != reflect.Pointer {
v = &v
}
s.ValueFuzzed(v)
@@ -383,7 +383,7 @@ func (v *ValidationTester) validate() field.ErrorList {
}
rt := reflect.TypeOf(v.value)
for rt.Kind() == reflect.Ptr {
for rt.Kind() == reflect.Pointer {
rt = rt.Elem()
}
pkgName := strings.Split(rt.String(), ".")[0]
@@ -18,7 +18,7 @@ package load
import (
"bytes"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
@@ -40,14 +40,14 @@ var defaultConfig = &api.PodSecurityConfiguration{
func writeTempFile(t *testing.T, content string) string {
t.Helper()
file, err := ioutil.TempFile("", "podsecurityconfig")
file, err := os.CreateTemp("", "podsecurityconfig")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
utiltesting.CloseAndRemove(t, file)
})
if err := ioutil.WriteFile(file.Name(), []byte(content), 0600); err != nil {
if err := os.WriteFile(file.Name(), []byte(content), 0600); err != nil {
t.Fatal(err)
}
return file.Name()
@@ -23,7 +23,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -182,7 +182,7 @@ func (s *Server) HandleValidate(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
limitedReader := &io.LimitedReader{R: r.Body, N: maxRequestSize}
if body, err = ioutil.ReadAll(limitedReader); err != nil {
if body, err = io.ReadAll(limitedReader); err != nil {
logger.Error(err, "unable to read the body from the incoming request")
http.Error(w, "unable to read the body from the incoming request", http.StatusBadRequest)
return
@@ -18,7 +18,6 @@ package test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -137,7 +136,7 @@ func testFixtureFile(t *testing.T, dir, name string, pod *corev1.Pod) string {
pod = pod.DeepCopy()
pod.Name = name
expectedYAML, _ := ioutil.ReadFile(filename)
expectedYAML, _ := os.ReadFile(filename)
jsonData, err := runtime.Encode(scheme.Codecs.LegacyCodec(corev1.SchemeGroupVersion), pod)
if err != nil {
@@ -159,7 +158,7 @@ func testFixtureFile(t *testing.T, dir, name string, pod *corev1.Pod) string {
if err := os.MkdirAll(dir, os.FileMode(0755)); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filename, []byte(yamlData), os.FileMode(0755)); err == nil {
if err := os.WriteFile(filename, []byte(yamlData), os.FileMode(0755)); err == nil {
t.Logf("Updated data in %s", filename)
t.Logf("Verify the diff, commit changes, and rerun the tests")
} else {