Merge pull request #111572 from inosato/remove-ioutil-from-kubectl

Remove ioutil from kubectl
This commit is contained in:
Kubernetes Prow Robot 2022-12-09 15:41:59 -08:00 committed by GitHub
commit c98bde46c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 267 additions and 311 deletions

View File

@ -18,7 +18,7 @@ package annotate
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
@ -533,7 +533,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"10"}}`,
))}, nil
default:
@ -543,7 +543,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
case "PATCH":
switch req.URL.Path {
case "/namespaces/test/pods/foo":
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -553,7 +553,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"11"}}`,
))}, nil
default:

View File

@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -232,7 +231,7 @@ func readBytesFromFile(t *testing.T, filename string) []byte {
}
defer file.Close()
data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
t.Fatal(err)
}
@ -345,7 +344,7 @@ func validatePatchApplication(t *testing.T, req *http.Request, patchType types.P
t.Fatalf("unexpected content-type expected: %s but actual %s\n", wanted, got)
}
patch, err := ioutil.ReadAll(req.Body)
patch, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -398,9 +397,9 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
switch p {
case pathCM + "/test0":
body = ioutil.NopCloser(bytes.NewReader(configMapList[0]))
body = io.NopCloser(bytes.NewReader(configMapList[0]))
case pathCM + "/test1":
body = ioutil.NopCloser(bytes.NewReader(configMapList[1]))
body = io.NopCloser(bytes.NewReader(configMapList[1]))
default:
t.Errorf("unexpected request to %s", p)
}
@ -531,10 +530,10 @@ func TestRunApplyViewLastApplied(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(test.respBytes))
bodyRC := io.NopCloser(bytes.NewReader(test.respBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == "/namespaces/test/replicationcontrollers" && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(test.respBytes))
bodyRC := io.NopCloser(bytes.NewReader(test.respBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == "/namespaces/test/replicationcontrollers/no-match" && m == "GET":
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.Pod{})}, nil
@ -587,10 +586,10 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(rcBytes))
bodyRC := io.NopCloser(bytes.NewReader(rcBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "PATCH":
bodyRC := ioutil.NopCloser(bytes.NewReader(rcBytes))
bodyRC := io.NopCloser(bytes.NewReader(rcBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -632,11 +631,11 @@ func TestApplyObject(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "PATCH":
validatePatchApplication(t, req, types.StrategicMergePatchType)
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -681,11 +680,11 @@ func TestApplyPruneObjects(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "PATCH":
validatePatchApplication(t, req, types.StrategicMergePatchType)
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1043,7 +1042,7 @@ func TestApplyCSAMigration(t *testing.T) {
// During retry loop for patch fetch is performed.
// keep returning the unchanged data
if patches < targetPatches {
bodyRC := ioutil.NopCloser(bytes.NewReader(rcWithManagedFields))
bodyRC := io.NopCloser(bytes.NewReader(rcWithManagedFields))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
}
@ -1059,7 +1058,7 @@ func TestApplyCSAMigration(t *testing.T) {
case 0:
// initial apply.
// Just return the same object but with managed fields
bodyRC := ioutil.NopCloser(bytes.NewReader(rcWithManagedFields))
bodyRC := io.NopCloser(bytes.NewReader(rcWithManagedFields))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case 1:
// Second apply should include only last apply annotation unmodified
@ -1068,12 +1067,12 @@ func TestApplyCSAMigration(t *testing.T) {
// just return the same object unmodified. It is not so important
// for this test for the last-applied to appear in new field
// manager response, only that the client asks the server to do it
bodyRC := ioutil.NopCloser(bytes.NewReader(rcWithManagedFields))
bodyRC := io.NopCloser(bytes.NewReader(rcWithManagedFields))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case 2, 3:
// Before the last apply we have formed our JSONPAtch so it
// should reply now with the upgraded object
bodyRC := ioutil.NopCloser(bytes.NewReader(postPatchData))
bodyRC := io.NopCloser(bytes.NewReader(postPatchData))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
require.Fail(t, "sent more apply requests than expected")
@ -1085,13 +1084,13 @@ func TestApplyCSAMigration(t *testing.T) {
}()
// Require that the patch is equal to what is expected
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
require.Equal(t, expectedPatch, body)
switch patches {
case targetPatches - 1:
bodyRC := ioutil.NopCloser(bytes.NewReader(postPatchData))
bodyRC := io.NopCloser(bytes.NewReader(postPatchData))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
// Return conflict until the client has retried enough times
@ -1186,11 +1185,11 @@ func TestApplyObjectOutput(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "PATCH":
validatePatchApplication(t, req, types.StrategicMergePatchType)
bodyRC := ioutil.NopCloser(bytes.NewReader(postPatchData))
bodyRC := io.NopCloser(bytes.NewReader(postPatchData))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1240,19 +1239,19 @@ func TestApplyRetry(t *testing.T) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
getCount++
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "PATCH":
if firstPatch {
firstPatch = false
statusErr := apierrors.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
bodyBytes, _ := json.Marshal(statusErr)
bodyErr := ioutil.NopCloser(bytes.NewReader(bodyBytes))
bodyErr := io.NopCloser(bytes.NewReader(bodyBytes))
return &http.Response{StatusCode: http.StatusConflict, Header: cmdtesting.DefaultHeader(), Body: bodyErr}, nil
}
retry = true
validatePatchApplication(t, req, types.StrategicMergePatchType)
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1299,11 +1298,11 @@ func TestApplyNonExistObject(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/api/v1/namespaces/test" && m == "GET":
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader(nil))}, nil
case p == pathNameRC && m == "GET":
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader(nil))}, nil
case p == pathRC && m == "POST":
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1345,17 +1344,17 @@ func TestApplyEmptyPatch(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/api/v1/namespaces/test" && m == "GET":
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader(nil))}, nil
case p == pathNameRC && m == "GET":
if body == nil {
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader(nil))}, nil
}
bodyRC := ioutil.NopCloser(bytes.NewReader(body))
bodyRC := io.NopCloser(bytes.NewReader(body))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "POST":
body, _ = ioutil.ReadAll(req.Body)
body, _ = io.ReadAll(req.Body)
verifyPost = true
bodyRC := ioutil.NopCloser(bytes.NewReader(body))
bodyRC := io.NopCloser(bytes.NewReader(body))
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1417,18 +1416,18 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathRC && m == "PATCH":
validatePatchApplication(t, req, types.StrategicMergePatchType)
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == pathSVC && m == "GET":
bodySVC := ioutil.NopCloser(bytes.NewReader(currentSVC))
bodySVC := io.NopCloser(bytes.NewReader(currentSVC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodySVC}, nil
case p == pathSVC && m == "PATCH":
validatePatchApplication(t, req, types.StrategicMergePatchType)
bodySVC := ioutil.NopCloser(bytes.NewReader(currentSVC))
bodySVC := io.NopCloser(bytes.NewReader(currentSVC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodySVC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1499,10 +1498,10 @@ func TestApplyNULLPreservation(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == deploymentPath && m == "GET":
body := ioutil.NopCloser(bytes.NewReader(deploymentBytes))
body := io.NopCloser(bytes.NewReader(deploymentBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
case p == deploymentPath && m == "PATCH":
patch, err := ioutil.ReadAll(req.Body)
patch, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -1524,7 +1523,7 @@ func TestApplyNULLPreservation(t *testing.T) {
// The real API server would had returned the patched object but Kubectl
// is ignoring the actual return object.
// TODO: Make this match actual server behavior by returning the patched object.
body := ioutil.NopCloser(bytes.NewReader(deploymentBytes))
body := io.NopCloser(bytes.NewReader(deploymentBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -1575,7 +1574,7 @@ func TestUnstructuredApply(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == path && m == "GET":
body := ioutil.NopCloser(bytes.NewReader(curr))
body := io.NopCloser(bytes.NewReader(curr))
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
@ -1584,7 +1583,7 @@ func TestUnstructuredApply(t *testing.T) {
validatePatchApplication(t, req, types.MergePatchType)
verifiedPatch = true
body := ioutil.NopCloser(bytes.NewReader(curr))
body := io.NopCloser(bytes.NewReader(curr))
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
@ -1640,7 +1639,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == path && m == "GET":
body := ioutil.NopCloser(bytes.NewReader(serversideData))
body := io.NopCloser(bytes.NewReader(serversideData))
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
@ -1648,7 +1647,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
case p == path && m == "PATCH":
// In idempotent updates, kubectl will resolve to an empty patch and not send anything to the server
// Thus, if we reach this branch, kubectl is unnecessarily sending a patch.
patch, err := ioutil.ReadAll(req.Body)
patch, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -1742,16 +1741,16 @@ func TestRunApplySetLastApplied(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == pathRC && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == noAnnotationPath && m == "GET":
bodyRC := ioutil.NopCloser(bytes.NewReader(noAnnotationRC))
bodyRC := io.NopCloser(bytes.NewReader(noAnnotationRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == noExistPath && m == "GET":
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.Pod{})}, nil
case p == pathRC && m == "PATCH":
checkPatchString(t, req)
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case p == "/api/v1/namespaces/test" && m == "GET":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.Namespace{})}, nil
@ -1785,7 +1784,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
func checkPatchString(t *testing.T, req *http.Request) {
checkString := string(readBytesFromFile(t, filenameRCPatchTest))
patch, err := ioutil.ReadAll(req.Body)
patch, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -1837,7 +1836,7 @@ func TestForceApply(t *testing.T) {
case strings.HasSuffix(p, pathRC) && m == "GET":
if deleted {
counts["getNotFound"]++
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte{}))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte{}))}, nil
}
counts["getOk"]++
var bodyRC io.ReadCloser
@ -1848,9 +1847,9 @@ func TestForceApply(t *testing.T) {
if err != nil {
t.Fatal(err)
}
bodyRC = ioutil.NopCloser(bytes.NewReader(rcBytes))
bodyRC = io.NopCloser(bytes.NewReader(rcBytes))
} else {
bodyRC = ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC = io.NopCloser(bytes.NewReader(currentRC))
}
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case strings.HasSuffix(p, pathRCList) && m == "GET":
@ -1867,14 +1866,14 @@ func TestForceApply(t *testing.T) {
if err != nil {
t.Fatal(err)
}
bodyRCList := ioutil.NopCloser(bytes.NewReader(listBytes))
bodyRCList := io.NopCloser(bytes.NewReader(listBytes))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRCList}, nil
case strings.HasSuffix(p, pathRC) && m == "PATCH":
counts["patch"]++
if counts["patch"] <= 6 {
statusErr := apierrors.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
bodyBytes, _ := json.Marshal(statusErr)
bodyErr := ioutil.NopCloser(bytes.NewReader(bodyBytes))
bodyErr := io.NopCloser(bytes.NewReader(bodyBytes))
return &http.Response{StatusCode: http.StatusConflict, Header: cmdtesting.DefaultHeader(), Body: bodyErr}, nil
}
t.Fatalf("unexpected request: %#v after %v tries\n%#v", req.URL, counts["patch"], req)
@ -1882,18 +1881,18 @@ func TestForceApply(t *testing.T) {
case strings.HasSuffix(p, pathRC) && m == "DELETE":
counts["delete"]++
deleted = true
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case strings.HasSuffix(p, pathRC) && m == "PUT":
counts["put"]++
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
isScaledDownToZero = true
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
case strings.HasSuffix(p, pathRCList) && m == "POST":
counts["post"]++
deleted = false
isScaledDownToZero = false
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)

View File

@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"strings"
@ -154,7 +153,7 @@ func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
}
} else {
if o.Quiet {
o.Out = ioutil.Discard
o.Out = io.Discard
}
switch len(args) {

View File

@ -19,7 +19,7 @@ package auth
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -122,8 +122,8 @@ func TestRunAccessCheck(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test.o.Out = ioutil.Discard
test.o.ErrOut = ioutil.Discard
test.o.Out = io.Discard
test.o.ErrOut = io.Discard
tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup()
@ -139,7 +139,7 @@ func TestRunAccessCheck(t *testing.T) {
t.Errorf("%s: expected %v, got %v", test.name, expectPath, req.URL.Path)
return nil, nil
}
bodyBits, err := ioutil.ReadAll(req.Body)
bodyBits, err := io.ReadAll(req.Body)
if err != nil {
t.Errorf("%s: %v", test.name, err)
return nil, nil
@ -154,7 +154,7 @@ func TestRunAccessCheck(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
fmt.Sprintf(`{"kind":"SelfSubjectAccessReview","apiVersion":"authorization.k8s.io/v1","status":{"allowed":%v}}`, test.allowed),
)),
},
@ -207,7 +207,7 @@ func TestRunAccessList(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/apis/authorization.k8s.io/v1/selfsubjectrulesreviews":
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, getSelfSubjectRulesReview()))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, getSelfSubjectRulesReview()))))
return &http.Response{StatusCode: http.StatusOK, Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)

View File

@ -19,7 +19,7 @@ package auth
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"
@ -137,7 +137,7 @@ func TestWhoAmIRun(t *testing.T) {
var b bytes.Buffer
test.o.Out = &b
test.o.ErrOut = ioutil.Discard
test.o.ErrOut = io.Discard
tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup()

View File

@ -18,7 +18,7 @@ package certificates
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
@ -193,7 +193,7 @@ func TestCertificates(t *testing.T) {
actions = append(actions, req.Method+" "+req.URL.Path)
switch p, m := req.URL.Path, req.Method; {
case tc.nov1 && strings.HasPrefix(p, "/apis/certificates.k8s.io/v1/"):
return &http.Response{StatusCode: http.StatusNotFound, Body: ioutil.NopCloser(bytes.NewBuffer([]byte{}))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Body: io.NopCloser(bytes.NewBuffer([]byte{}))}, nil
case p == "/apis/certificates.k8s.io/v1/certificatesigningrequests/missing" && m == http.MethodGet:
return &http.Response{StatusCode: http.StatusNotFound}, nil

View File

@ -17,7 +17,6 @@ limitations under the License.
package clusterinfo
import (
"io/ioutil"
"os"
"path"
"testing"
@ -57,7 +56,7 @@ func TestSetupOutputWriterNoOp(t *testing.T) {
func TestSetupOutputWriterFile(t *testing.T) {
file := "output"
extension := ".json"
dir, err := ioutil.TempDir(os.TempDir(), "out")
dir, err := os.MkdirTemp(os.TempDir(), "out")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -75,7 +74,7 @@ func TestSetupOutputWriterFile(t *testing.T) {
output := "some data here"
writer.Write([]byte(output))
data, err := ioutil.ReadFile(fullPath)
data, err := os.ReadFile(fullPath)
if err != nil {
t.Errorf("unexpected error: %v", err)
}

View File

@ -18,7 +18,6 @@ package cmd
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
@ -178,7 +177,7 @@ func (h *testPluginHandler) Lookup(filename string) (string, bool) {
return "", false
}
plugins, err := ioutil.ReadDir(h.pluginsDirectory)
plugins, err := os.ReadDir(h.pluginsDirectory)
if err != nil {
h.err = err
return "", false

View File

@ -18,7 +18,6 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"path"
"reflect"
@ -261,10 +260,10 @@ func TestAdditionalAuth(t *testing.T) {
}
func TestEmbedClientCert(t *testing.T) {
fakeCertFile, _ := ioutil.TempFile(os.TempDir(), "")
fakeCertFile, _ := os.CreateTemp(os.TempDir(), "")
defer os.Remove(fakeCertFile.Name())
fakeData := []byte("fake-data")
ioutil.WriteFile(fakeCertFile.Name(), fakeData, 0600)
os.WriteFile(fakeCertFile.Name(), fakeData, 0600)
expectedConfig := newRedFederalCowHammerConfig()
authInfo := clientcmdapi.NewAuthInfo()
authInfo.ClientCertificateData = fakeData
@ -280,10 +279,10 @@ func TestEmbedClientCert(t *testing.T) {
}
func TestEmbedClientKey(t *testing.T) {
fakeKeyFile, _ := ioutil.TempFile(os.TempDir(), "")
fakeKeyFile, _ := os.CreateTemp(os.TempDir(), "")
defer os.Remove(fakeKeyFile.Name())
fakeData := []byte("fake-data")
ioutil.WriteFile(fakeKeyFile.Name(), fakeData, 0600)
os.WriteFile(fakeKeyFile.Name(), fakeData, 0600)
expectedConfig := newRedFederalCowHammerConfig()
authInfo := clientcmdapi.NewAuthInfo()
authInfo.ClientKeyData = fakeData
@ -326,7 +325,7 @@ func TestEmbedNoKeyOrCertDisallowed(t *testing.T) {
}
func TestEmptyTokenAndCertAllowed(t *testing.T) {
fakeCertFile, _ := ioutil.TempFile(os.TempDir(), "cert-file")
fakeCertFile, _ := os.CreateTemp(os.TempDir(), "cert-file")
defer os.Remove(fakeCertFile.Name())
expectedConfig := newRedFederalCowHammerConfig()
authInfo := clientcmdapi.NewAuthInfo()
@ -569,7 +568,7 @@ func TestUnsetBytes(t *testing.T) {
}
func TestCAClearsInsecure(t *testing.T) {
fakeCAFile, _ := ioutil.TempFile(os.TempDir(), "ca-file")
fakeCAFile, _ := os.CreateTemp(os.TempDir(), "ca-file")
defer os.Remove(fakeCAFile.Name())
clusterInfoWithInsecure := clientcmdapi.NewCluster()
clusterInfoWithInsecure.InsecureSkipTLSVerify = true
@ -638,10 +637,10 @@ func TestInsecureClearsCA(t *testing.T) {
}
func TestCADataClearsCA(t *testing.T) {
fakeCAFile, _ := ioutil.TempFile(os.TempDir(), "")
fakeCAFile, _ := os.CreateTemp(os.TempDir(), "")
defer os.Remove(fakeCAFile.Name())
fakeData := []byte("cadata")
ioutil.WriteFile(fakeCAFile.Name(), fakeData, 0600)
os.WriteFile(fakeCAFile.Name(), fakeData, 0600)
clusterInfoWithCAData := clientcmdapi.NewCluster()
clusterInfoWithCAData.CertificateAuthorityData = fakeData
@ -852,7 +851,7 @@ func TestToBool(t *testing.T) {
}
func testConfigCommand(args []string, startingConfig clientcmdapi.Config, t *testing.T) (string, clientcmdapi.Config) {
fakeKubeFile, _ := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, _ := os.CreateTemp(os.TempDir(), "")
defer os.Remove(fakeKubeFile.Name())
err := clientcmd.WriteToFile(startingConfig, fakeKubeFile.Name())
if err != nil {

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
@ -57,7 +56,7 @@ func TestCurrentContextWithUnsetContext(t *testing.T) {
}
func (test currentContextTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -19,7 +19,6 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
@ -53,7 +52,7 @@ func TestDeleteCluster(t *testing.T) {
}
func (test deleteClusterTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -19,7 +19,6 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
@ -53,7 +52,7 @@ func TestDeleteContext(t *testing.T) {
}
func (test deleteContextTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
@ -57,7 +56,7 @@ func TestGetClustersEmpty(t *testing.T) {
}
func (test getClustersTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package config
import (
"io/ioutil"
"os"
"testing"
@ -144,7 +143,7 @@ func TestGetContextsSelectOneOfTwo(t *testing.T) {
}
func (test getContextsTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -19,7 +19,6 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
@ -103,7 +102,7 @@ func TestRenameToAlreadyExistingContext(t *testing.T) {
}
func (test renameContextTest) run(t *testing.T) {
fakeKubeFile, _ := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, _ := os.CreateTemp(os.TempDir(), "")
defer os.Remove(fakeKubeFile.Name())
err := clientcmd.WriteToFile(test.initialConfig, fakeKubeFile.Name())
if err != nil {

View File

@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -147,7 +146,7 @@ func (o *setClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluster)
if o.certificateAuthority.Provided() {
caPath := o.certificateAuthority.Value()
if o.embedCAData.Value() {
modifiedCluster.CertificateAuthorityData, _ = ioutil.ReadFile(caPath)
modifiedCluster.CertificateAuthorityData, _ = os.ReadFile(caPath)
modifiedCluster.InsecureSkipTLSVerify = false
modifiedCluster.CertificateAuthority = ""
} else {

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
@ -183,7 +182,7 @@ func TestModifyClusterServerAndTLS(t *testing.T) {
}
func (test setClusterTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
@ -107,7 +106,7 @@ func TestModifyCurrentContext(t *testing.T) {
}
func (test setContextTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -221,7 +220,7 @@ func (o *setCredentialsOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut
if o.clientCertificate.Provided() {
certPath := o.clientCertificate.Value()
if o.embedCertData.Value() {
modifiedAuthInfo.ClientCertificateData, _ = ioutil.ReadFile(certPath)
modifiedAuthInfo.ClientCertificateData, _ = os.ReadFile(certPath)
modifiedAuthInfo.ClientCertificate = ""
} else {
certPath, _ = filepath.Abs(certPath)
@ -234,7 +233,7 @@ func (o *setCredentialsOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut
if o.clientKey.Provided() {
keyPath := o.clientKey.Value()
if o.embedCertData.Value() {
modifiedAuthInfo.ClientKeyData, _ = ioutil.ReadFile(keyPath)
modifiedAuthInfo.ClientKeyData, _ = os.ReadFile(keyPath)
modifiedAuthInfo.ClientKey = ""
} else {
keyPath, _ = filepath.Abs(keyPath)

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"reflect"
"testing"
@ -454,7 +453,7 @@ func TestSetCredentials(t *testing.T) {
test.run(t)
}
func (test setCredentialsTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
@ -55,7 +54,7 @@ func TestSetConfigCurrentContext(t *testing.T) {
}
func (test setConfigTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
@ -106,7 +105,7 @@ func TestUnsetUnexistConfig(t *testing.T) {
}
func (test unsetConfigTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
@ -71,7 +70,7 @@ func TestUseContext(t *testing.T) {
}
func (test useContextTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package config
import (
"io/ioutil"
"os"
"testing"
@ -294,7 +293,7 @@ users:
}
func (test viewClusterTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
@ -129,7 +128,7 @@ func NewCmdCp(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.C
// listing the entire content of the current directory which could
// be too many choices for the user)
if len(comps) > 0 && len(toComplete) > 0 {
if files, err := ioutil.ReadDir("."); err == nil {
if files, err := os.ReadDir("."); err == nil {
for _, file := range files {
filename := file.Name()
if strings.HasPrefix(filename, toComplete) {
@ -423,7 +422,7 @@ func recursiveTar(srcDir, srcFile localPath, destDir, destFile remotePath, tw *t
return err
}
if stat.IsDir() {
files, err := ioutil.ReadDir(fpath)
files, err := os.ReadDir(fpath)
if err != nil {
return err
}

View File

@ -21,7 +21,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -309,15 +308,15 @@ func checkErr(t *testing.T, err error) {
}
func TestTarUntar(t *testing.T) {
dir, err := ioutil.TempDir("", "input")
dir, err := os.MkdirTemp("", "input")
checkErr(t, err)
dir = dir + "/"
dir2, err := ioutil.TempDir("", "output")
dir2, err := os.MkdirTemp("", "output")
checkErr(t, err)
dir2 = dir2 + "/"
dir3, err := ioutil.TempDir("", "dir")
dir3, err := os.MkdirTemp("", "dir")
checkErr(t, err)
defer func() {
@ -450,11 +449,11 @@ func TestTarUntar(t *testing.T) {
}
func TestTarUntarWrongPrefix(t *testing.T) {
dir, err := ioutil.TempDir("", "input")
dir, err := os.MkdirTemp("", "input")
checkErr(t, err)
dir = dir + "/"
dir2, err := ioutil.TempDir("", "output")
dir2, err := os.MkdirTemp("", "output")
checkErr(t, err)
defer func() {
@ -483,8 +482,8 @@ func TestTarUntarWrongPrefix(t *testing.T) {
}
func TestTarDestinationName(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "input")
dir2, err2 := ioutil.TempDir(os.TempDir(), "output")
dir, err := os.MkdirTemp(os.TempDir(), "input")
dir2, err2 := os.MkdirTemp(os.TempDir(), "output")
if err != nil || err2 != nil {
t.Errorf("unexpected error: %v | %v", err, err2)
t.FailNow()
@ -554,7 +553,7 @@ func TestTarDestinationName(t *testing.T) {
}
func TestBadTar(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "dest")
dir, err := os.MkdirTemp(os.TempDir(), "dest")
if err != nil {
t.Errorf("unexpected error: %v ", err)
t.FailNow()
@ -614,7 +613,7 @@ func TestCopyToPod(t *testing.T) {
NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
responsePod := &v1.Pod{}
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, responsePod))))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, responsePod))))}, nil
}),
}
@ -623,7 +622,7 @@ func TestCopyToPod(t *testing.T) {
cmd := NewCmdCp(tf, ioStreams)
srcFile, err := ioutil.TempDir("", "test")
srcFile, err := os.MkdirTemp("", "test")
if err != nil {
t.Errorf("unexpected error: %v", err)
t.FailNow()
@ -685,7 +684,7 @@ func TestCopyToPodNoPreserve(t *testing.T) {
NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
responsePod := &v1.Pod{}
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, responsePod))))}, nil
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, responsePod))))}, nil
}),
}
@ -694,7 +693,7 @@ func TestCopyToPodNoPreserve(t *testing.T) {
cmd := NewCmdCp(tf, ioStreams)
srcFile, err := ioutil.TempDir("", "test")
srcFile, err := os.MkdirTemp("", "test")
if err != nil {
t.Errorf("unexpected error: %v", err)
t.FailNow()
@ -769,7 +768,7 @@ func TestValidate(t *testing.T) {
}
func TestUntar(t *testing.T) {
testdir, err := ioutil.TempDir("", "test-untar")
testdir, err := os.MkdirTemp("", "test-untar")
require.NoError(t, err)
defer os.RemoveAll(testdir)
t.Logf("Test base: %s", testdir)
@ -935,7 +934,7 @@ func TestUntar(t *testing.T) {
}
func TestUntar_SingleFile(t *testing.T) {
testdir, err := ioutil.TempDir("", "test-untar")
testdir, err := os.MkdirTemp("", "test-untar")
require.NoError(t, err)
defer os.RemoveAll(testdir)
@ -981,7 +980,7 @@ func createTmpFile(t *testing.T, filepath, data string) {
}
func cmpFileData(t *testing.T, filePath, data string) {
actual, err := ioutil.ReadFile(filePath)
actual, err := os.ReadFile(filePath)
require.NoError(t, err)
assert.EqualValues(t, data, actual)
}

View File

@ -19,7 +19,6 @@ package create
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
@ -331,13 +330,13 @@ func handleConfigMapFromFileSources(configMap *corev1.ConfigMap, fileSources []s
if strings.Contains(fileSource, "=") {
return fmt.Errorf("cannot give a key name for a directory path")
}
fileList, err := ioutil.ReadDir(filePath)
fileList, err := os.ReadDir(filePath)
if err != nil {
return fmt.Errorf("error listing files in %s: %v", filePath, err)
}
for _, item := range fileList {
itemPath := path.Join(filePath, item.Name())
if item.Mode().IsRegular() {
if item.Type().IsRegular() {
keyName = item.Name()
err = addKeyFromFileToConfigMap(configMap, keyName, itemPath)
if err != nil {
@ -385,7 +384,7 @@ func handleConfigMapFromEnvFileSources(configMap *corev1.ConfigMap, envFileSourc
// addKeyFromFileToConfigMap adds a key with the given name to a ConfigMap, populating
// the value with the content of the given file path, or returns an error.
func addKeyFromFileToConfigMap(configMap *corev1.ConfigMap, keyName, filePath string) error {
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
return err
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package create
import (
"io/ioutil"
"os"
"testing"
@ -465,7 +464,7 @@ func setupEnvFile(lines [][]string) func(*testing.T, *ConfigMapOptions) func() {
files := []*os.File{}
filenames := configMapOptions.EnvFileSources
for _, filename := range filenames {
file, err := ioutil.TempFile("", filename)
file, err := os.CreateTemp("", filename)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -489,11 +488,11 @@ func setupEnvFile(lines [][]string) func(*testing.T, *ConfigMapOptions) func() {
func setupBinaryFile(data []byte) func(*testing.T, *ConfigMapOptions) func() {
return func(t *testing.T, configMapOptions *ConfigMapOptions) func() {
tmp, _ := ioutil.TempDir("", "")
tmp, _ := os.MkdirTemp("", "")
files := configMapOptions.FileSources
for i, file := range files {
f := tmp + "/" + file
ioutil.WriteFile(f, data, 0644)
os.WriteFile(f, data, 0644)
configMapOptions.FileSources[i] = f
}
return func() {

View File

@ -18,7 +18,7 @@ package create
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -45,7 +45,7 @@ func TestCreateDeployment(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
}, nil
}),
}
@ -76,7 +76,7 @@ func TestCreateDeploymentWithPort(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
}, nil
}),
}
@ -107,7 +107,7 @@ func TestCreateDeploymentWithReplicas(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
}, nil
}),
}
@ -137,7 +137,7 @@ func TestCreateDeploymentNoImage(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
}, nil
}),
}

View File

@ -18,7 +18,7 @@ package create
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -43,7 +43,7 @@ func TestCreatePriorityClass(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(&bytes.Buffer{}),
Body: io.NopCloser(&bytes.Buffer{}),
}, nil
}),
}

View File

@ -19,7 +19,6 @@ package create
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
@ -352,13 +351,13 @@ func handleSecretFromFileSources(secret *corev1.Secret, fileSources []string) er
if strings.Contains(fileSource, "=") {
return fmt.Errorf("cannot give a key name for a directory path")
}
fileList, err := ioutil.ReadDir(filePath)
fileList, err := os.ReadDir(filePath)
if err != nil {
return fmt.Errorf("error listing files in %s: %v", filePath, err)
}
for _, item := range fileList {
itemPath := path.Join(filePath, item.Name())
if item.Mode().IsRegular() {
if item.Type().IsRegular() {
keyName = item.Name()
if err := addKeyFromFileToSecret(secret, keyName, itemPath); err != nil {
return err
@ -407,7 +406,7 @@ func handleSecretFromEnvFileSources(secret *corev1.Secret, envFileSources []stri
// addKeyFromFileToSecret adds a key with the given name to a Secret, populating
// the value with the content of the given file path, or returns an error.
func addKeyFromFileToSecret(secret *corev1.Secret, keyName, filePath string) error {
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
return err
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package create
import (
"io/ioutil"
"os"
"testing"
@ -540,7 +539,7 @@ func setupSecretEnvFile(lines [][]string) func(*testing.T, *CreateSecretOptions)
files := []*os.File{}
filenames := secretOptions.EnvFileSources
for _, filename := range filenames {
file, err := ioutil.TempFile("", filename)
file, err := os.CreateTemp("", filename)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -564,11 +563,11 @@ func setupSecretEnvFile(lines [][]string) func(*testing.T, *CreateSecretOptions)
func setupSecretBinaryFile(data []byte) func(*testing.T, *CreateSecretOptions) func() {
return func(t *testing.T, secretOptions *CreateSecretOptions) func() {
tmp, _ := ioutil.TempDir("", "")
tmp, _ := os.MkdirTemp("", "")
files := secretOptions.FileSources
for i, file := range files {
f := tmp + "/" + file
ioutil.WriteFile(f, data, 0644)
os.WriteFile(f, data, 0644)
secretOptions.FileSources[i] = f
}
return func() {

View File

@ -20,7 +20,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"os"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
@ -258,7 +258,7 @@ func (o *CreateSecretTLSOptions) createSecretTLS() (*corev1.Secret, error) {
// readFile just reads a file into a byte array.
func readFile(file string) ([]byte, error) {
b, err := ioutil.ReadFile(file)
b, err := os.ReadFile(file)
if err != nil {
return []byte{}, fmt.Errorf("Cannot read file %v, %v", file, err)
}

View File

@ -19,7 +19,7 @@ package create
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"reflect"
"testing"
@ -280,7 +280,7 @@ status:
if req.URL.Path != test.expectRequestPath {
t.Fatalf("expected %q, got %q", test.expectRequestPath, req.URL.Path)
}
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -293,7 +293,7 @@ status:
return &http.Response{
StatusCode: code,
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
Body: io.NopCloser(bytes.NewBuffer(body)),
}, nil
}),
}

View File

@ -19,7 +19,6 @@ package delete
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
@ -104,7 +103,7 @@ func hasExpectedPropagationPolicy(body io.ReadCloser, policy *metav1.DeletionPro
return body == nil && policy == nil
}
var parsedBody metav1.DeleteOptions
rawBody, _ := ioutil.ReadAll(body)
rawBody, _ := io.ReadAll(body)
json.Unmarshal(rawBody, &parsedBody)
if parsedBody.PropagationPolicy == nil {
return false

View File

@ -19,7 +19,6 @@ package diff
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@ -286,7 +285,7 @@ type Directory struct {
// CreateDirectory does create the actual disk directory, and return a
// new representation of it.
func CreateDirectory(prefix string) (*Directory, error) {
name, err := ioutil.TempDir("", prefix+"-")
name, err := os.MkdirTemp("", prefix+"-")
if err != nil {
return nil, err
}

View File

@ -19,7 +19,6 @@ package diff
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -134,7 +133,7 @@ func TestDiffVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fcontent, err := ioutil.ReadFile(path.Join(diff.Dir.Name, obj.Name()))
fcontent, err := os.ReadFile(path.Join(diff.Dir.Name, obj.Name()))
if err != nil {
t.Fatal(err)
}
@ -157,7 +156,7 @@ func TestDirectory(t *testing.T) {
if !strings.HasPrefix(filepath.Base(dir.Name), "prefix") {
t.Fatalf(`Directory doesn't start with "prefix": %q`, dir.Name)
}
entries, err := ioutil.ReadDir(dir.Name)
entries, err := os.ReadDir(dir.Name)
if err != nil {
t.Fatal(err)
}
@ -172,7 +171,7 @@ func TestDirectory(t *testing.T) {
if err != nil {
t.Fatal(err)
}
entries, err = ioutil.ReadDir(dir.Name)
entries, err = os.ReadDir(dir.Name)
if err != nil {
t.Fatal(err)
}
@ -205,7 +204,7 @@ func TestDiffer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fcontent, err := ioutil.ReadFile(path.Join(diff.From.Dir.Name, obj.Name()))
fcontent, err := os.ReadFile(path.Join(diff.From.Dir.Name, obj.Name()))
if err != nil {
t.Fatal(err)
}
@ -214,7 +213,7 @@ func TestDiffer(t *testing.T) {
t.Fatalf("File has %q, expected %q", string(fcontent), econtent)
}
fcontent, err = ioutil.ReadFile(path.Join(diff.To.Dir.Name, obj.Name()))
fcontent, err = os.ReadFile(path.Join(diff.To.Dir.Name, obj.Name()))
if err != nil {
t.Fatal(err)
}
@ -290,12 +289,12 @@ metadata:
t.Fatal(err)
}
actualFromContent, _ := ioutil.ReadFile(path.Join(diff.From.Dir.Name, obj.Name()))
actualFromContent, _ := os.ReadFile(path.Join(diff.From.Dir.Name, obj.Name()))
if string(actualFromContent) != tc.expectedFromContent {
t.Fatalf("File has %q, expected %q", string(actualFromContent), tc.expectedFromContent)
}
actualToContent, _ := ioutil.ReadFile(path.Join(diff.To.Dir.Name, obj.Name()))
actualToContent, _ := os.ReadFile(path.Join(diff.To.Dir.Name, obj.Name()))
if string(actualToContent) != tc.expectedToContent {
t.Fatalf("File has %q, expected %q", string(actualToContent), tc.expectedToContent)
}

View File

@ -18,7 +18,7 @@ package drain
import (
"errors"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
@ -182,7 +182,7 @@ func TestCordon(t *testing.T) {
case m.isFor("PATCH", "/nodes/node2"):
fallthrough
case m.isFor("PATCH", "/nodes/node"):
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("%s: unexpected error: %v", test.description, err)
}
@ -833,7 +833,7 @@ func TestDrain(t *testing.T) {
case m.isFor("GET", "/replicationcontrollers"):
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.ReplicationControllerList{Items: test.rcs})}, nil
case m.isFor("PATCH", "/nodes/node"):
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("%s: unexpected error: %v", test.description, err)
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -98,20 +97,20 @@ func TestEdit(t *testing.T) {
body := []byte{}
if req.Body != nil {
body, err = ioutil.ReadAll(req.Body)
body, err = io.ReadAll(req.Body)
if err != nil {
t.Fatalf("%s, step %d: %v", name, i, err)
}
}
inputFile := filepath.Join("testdata", "testcase-"+name, step.Input)
expectedInput, err := ioutil.ReadFile(inputFile)
expectedInput, err := os.ReadFile(inputFile)
if err != nil {
t.Fatalf("%s, step %d: %v", name, i, err)
}
outputFile := filepath.Join("testdata", "testcase-"+name, step.Output)
resultingOutput, err := ioutil.ReadFile(outputFile)
resultingOutput, err := os.ReadFile(outputFile)
if err != nil {
t.Fatalf("%s, step %d: %v", name, i, err)
}
@ -123,13 +122,13 @@ func TestEdit(t *testing.T) {
if !bytes.Equal(body, expectedInput) {
if updateInputFixtures {
// Convenience to allow recapturing the input and persisting it here
ioutil.WriteFile(inputFile, body, os.FileMode(0644))
os.WriteFile(inputFile, body, os.FileMode(0644))
} else {
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
}
}
return &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(resultingOutput))}, nil
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader(resultingOutput))}, nil
}
if step.StepType != "request" {
t.Fatalf("%s, step %d: expected request step, got %s %s", name, i, req.Method, req.URL.Path)
@ -146,13 +145,13 @@ func TestEdit(t *testing.T) {
if !bytes.Equal(body, expectedInput) {
if updateInputFixtures {
// Convenience to allow recapturing the input and persisting it here
ioutil.WriteFile(inputFile, body, os.FileMode(0644))
os.WriteFile(inputFile, body, os.FileMode(0644))
} else {
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
}
}
return &http.Response{StatusCode: step.ResponseStatusCode, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(resultingOutput))}, nil
return &http.Response{StatusCode: step.ResponseStatusCode, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader(resultingOutput))}, nil
}
@ -202,7 +201,7 @@ func TestEdit(t *testing.T) {
name = testcaseName
testcase = EditTestCase{}
testcaseDir := filepath.Join("testdata", "testcase-"+name)
testcaseData, err := ioutil.ReadFile(filepath.Join(testcaseDir, "test.yaml"))
testcaseData, err := os.ReadFile(filepath.Join(testcaseDir, "test.yaml"))
if err != nil {
t.Fatalf("%s: %v", name, err)
}

View File

@ -20,7 +20,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
@ -85,7 +85,7 @@ func main() {
record = true
}
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
checkErr(err)
switch m, p := req.Method, req.URL.Path; {
@ -94,14 +94,14 @@ func main() {
panic("cannot post input with step already in progress")
}
filename := fmt.Sprintf("%d.original", len(tc.Steps))
checkErr(ioutil.WriteFile(filename, body, os.FileMode(0755)))
checkErr(os.WriteFile(filename, body, os.FileMode(0755)))
currentStep = &EditStep{StepType: "edit", Input: filename}
case m == "POST" && p == "/callback/out":
if currentStep == nil || currentStep.StepType != "edit" {
panic("cannot post output without posting input first")
}
filename := fmt.Sprintf("%d.edited", len(tc.Steps))
checkErr(ioutil.WriteFile(filename, body, os.FileMode(0755)))
checkErr(os.WriteFile(filename, body, os.FileMode(0755)))
currentStep.Output = filename
tc.Steps = append(tc.Steps, *currentStep)
currentStep = nil
@ -120,7 +120,7 @@ func main() {
checkErr(err)
defer resp.Body.Close()
bodyOut, err := ioutil.ReadAll(resp.Body)
bodyOut, err := io.ReadAll(resp.Body)
checkErr(err)
for k, vs := range resp.Header {
@ -134,8 +134,8 @@ func main() {
if record {
infile := fmt.Sprintf("%d.request", len(tc.Steps))
outfile := fmt.Sprintf("%d.response", len(tc.Steps))
checkErr(ioutil.WriteFile(infile, tryIndent(body), os.FileMode(0755)))
checkErr(ioutil.WriteFile(outfile, tryIndent(bodyOut), os.FileMode(0755)))
checkErr(os.WriteFile(infile, tryIndent(body), os.FileMode(0755)))
checkErr(os.WriteFile(outfile, tryIndent(bodyOut), os.FileMode(0755)))
tc.Steps = append(tc.Steps, EditStep{
StepType: "request",
Input: infile,
@ -150,7 +150,7 @@ func main() {
tcData, err := yaml.Marshal(tc)
checkErr(err)
checkErr(ioutil.WriteFile("test.yaml", tcData, os.FileMode(0755)))
checkErr(os.WriteFile("test.yaml", tcData, os.FileMode(0755)))
})))
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
@ -373,7 +372,7 @@ func TestSetupTTY(t *testing.T) {
stderr.Reset()
o.TTY = true
overrideStdin := ioutil.NopCloser(&bytes.Buffer{})
overrideStdin := io.NopCloser(&bytes.Buffer{})
overrideStdout := &bytes.Buffer{}
overrideStderr := &bytes.Buffer{}
o.overrideStreams = func() (io.ReadCloser, io.Writer, io.Writer) {

View File

@ -19,7 +19,6 @@ package get
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
@ -32,7 +31,7 @@ import (
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
testObject := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
customColumnsFile, err := ioutil.TempFile(os.TempDir(), "printers_jsonpath_flags")
customColumnsFile, err := os.CreateTemp(os.TempDir(), "printers_jsonpath_flags")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"path/filepath"
"reflect"
@ -746,7 +745,7 @@ func TestGetEmptyTable(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup()
emptyTable := ioutil.NopCloser(bytes.NewBufferString(`{
emptyTable := io.NopCloser(bytes.NewBufferString(`{
"kind":"Table",
"apiVersion":"meta.k8s.io/v1beta1",
"metadata":{
@ -959,7 +958,7 @@ func TestGetSortedObjectsUnstructuredTable(t *testing.T) {
t.Fatal(err)
}
// t.Log(string(unstructuredBytes))
body := ioutil.NopCloser(bytes.NewReader(unstructuredBytes))
body := io.NopCloser(bytes.NewReader(unstructuredBytes))
tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup()
@ -2844,7 +2843,7 @@ func watchBody(codec runtime.Codec, events []watch.Event) io.ReadCloser {
panic(err)
}
}
return ioutil.NopCloser(buf)
return io.NopCloser(buf)
}
var podColumns = []metav1.TableColumnDefinition{

View File

@ -19,7 +19,7 @@ package label
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"path/filepath"
"reflect"
@ -531,7 +531,7 @@ func TestLabelResourceVersion(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"10"}}`,
))}, nil
default:
@ -541,7 +541,7 @@ func TestLabelResourceVersion(t *testing.T) {
case "PATCH":
switch req.URL.Path {
case "/namespaces/test/pods/foo":
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
t.Fatal(err)
}
@ -551,7 +551,7 @@ func TestLabelResourceVersion(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"11"}}`,
))}, nil
default:
@ -602,7 +602,7 @@ func TestRunLabelMsg(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","labels":{"existing":"abc"}}}`,
))}, nil
default:
@ -615,7 +615,7 @@ func TestRunLabelMsg(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: cmdtesting.DefaultHeader(),
Body: ioutil.NopCloser(bytes.NewBufferString(
Body: io.NopCloser(bytes.NewBufferString(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","labels":{"existing":"abc"}}}`,
))}, nil
default:

View File

@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"sync"
@ -839,12 +838,12 @@ type responseWrapperMock struct {
}
func (r *responseWrapperMock) DoRaw(context.Context) ([]byte, error) {
data, _ := ioutil.ReadAll(r.data)
data, _ := io.ReadAll(r.data)
return data, r.err
}
func (r *responseWrapperMock) Stream(context.Context) (io.ReadCloser, error) {
return ioutil.NopCloser(r.data), r.err
return io.NopCloser(r.data), r.err
}
type logTestMock struct {

View File

@ -18,7 +18,7 @@ package patch
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
@ -219,7 +219,7 @@ func (o *PatchOptions) RunPatch() error {
var patchBytes []byte
if len(o.PatchFile) > 0 {
var err error
patchBytes, err = ioutil.ReadFile(o.PatchFile)
patchBytes, err = os.ReadFile(o.PatchFile)
if err != nil {
return fmt.Errorf("unable to read patch file: %v", err)
}

View File

@ -19,7 +19,6 @@ package plugin
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -166,7 +165,7 @@ func (o *PluginListOptions) ListPlugins() ([]string, []error) {
continue
}
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
if _, ok := err.(*os.PathError); ok {
fmt.Fprintf(o.ErrOut, "Unable to read directory %q from your PATH: %v. Skipping...\n", dir, err)

View File

@ -19,7 +19,7 @@ package plugin
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"path/filepath"
@ -83,8 +83,8 @@ func addPluginCommands(cmd *cobra.Command) {
kubectl := cmd.Root()
streams := genericclioptions.IOStreams{
In: &bytes.Buffer{},
Out: ioutil.Discard,
ErrOut: ioutil.Discard,
Out: io.Discard,
ErrOut: io.Discard,
}
o := &PluginListOptions{IOStreams: streams}

View File

@ -18,7 +18,6 @@ package plugin
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -29,11 +28,11 @@ import (
)
func TestPluginPathsAreUnaltered(t *testing.T) {
tempDir, err := ioutil.TempDir(os.TempDir(), "test-cmd-plugins")
tempDir, err := os.MkdirTemp(os.TempDir(), "test-cmd-plugins")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
tempDir2, err := ioutil.TempDir(os.TempDir(), "test-cmd-plugins2")
tempDir2, err := os.MkdirTemp(os.TempDir(), "test-cmd-plugins2")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@ -58,10 +57,10 @@ func TestPluginPathsAreUnaltered(t *testing.T) {
}
// write at least one valid plugin file
if _, err := ioutil.TempFile(tempDir, "kubectl-"); err != nil {
if _, err := os.CreateTemp(tempDir, "kubectl-"); err != nil {
t.Fatalf("unexpected error %v", err)
}
if _, err := ioutil.TempFile(tempDir2, "kubectl-"); err != nil {
if _, err := os.CreateTemp(tempDir2, "kubectl-"); err != nil {
t.Fatalf("unexpected error %v", err)
}
@ -81,7 +80,7 @@ func TestPluginPathsAreUnaltered(t *testing.T) {
}
func TestPluginPathsAreValid(t *testing.T) {
tempDir, err := ioutil.TempDir(os.TempDir(), "test-cmd-plugins")
tempDir, err := os.MkdirTemp(os.TempDir(), "test-cmd-plugins")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@ -107,7 +106,7 @@ func TestPluginPathsAreValid(t *testing.T) {
pluginPaths: []string{tempDir},
verifier: newFakePluginPathVerifier(),
pluginFile: func() (*os.File, error) {
return ioutil.TempFile(tempDir, "notkubectl-")
return os.CreateTemp(tempDir, "notkubectl-")
},
expectErr: "error: unable to find any kubectl plugins in your PATH\n",
},
@ -116,7 +115,7 @@ func TestPluginPathsAreValid(t *testing.T) {
pluginPaths: []string{tempDir, tempDir},
verifier: newFakePluginPathVerifier(),
pluginFile: func() (*os.File, error) {
return ioutil.TempFile(tempDir, "kubectl-")
return os.CreateTemp(tempDir, "kubectl-")
},
expectOut: "The following compatible plugins are available:",
},
@ -125,7 +124,7 @@ func TestPluginPathsAreValid(t *testing.T) {
pluginPaths: []string{tempDir, "", " "},
verifier: newFakePluginPathVerifier(),
pluginFile: func() (*os.File, error) {
return ioutil.TempFile(tempDir, "kubectl-")
return os.CreateTemp(tempDir, "kubectl-")
},
expectOut: "The following compatible plugins are available:",
},

View File

@ -18,7 +18,6 @@ package replace
import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
@ -331,7 +330,7 @@ func (o *ReplaceOptions) forceReplace() error {
stdinInUse := false
for i, filename := range o.DeleteOptions.FilenameOptions.Filenames {
if filename == "-" {
tempDir, err := ioutil.TempDir("", "kubectl_replace_")
tempDir, err := os.MkdirTemp("", "kubectl_replace_")
if err != nil {
return err
}

View File

@ -18,7 +18,7 @@ package rollout
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -80,7 +80,7 @@ func TestRolloutHistory(t *testing.T) {
case p == "/namespaces/test/deployments/foo" && m == "GET":
responseDeployment := &appsv1.Deployment{}
responseDeployment.Name = "foo"
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -176,12 +176,12 @@ func TestMultipleResourceRolloutHistory(t *testing.T) {
case p == "/namespaces/test/deployments/foo" && m == "GET":
responseDeployment := &appsv1.Deployment{}
responseDeployment.Name = "foo"
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
case p == "/namespaces/test/deployments/bar" && m == "GET":
responseDeployment := &appsv1.Deployment{}
responseDeployment.Name = "bar"
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -259,7 +259,7 @@ func TestRolloutHistoryWithOutput(t *testing.T) {
case p == "/namespaces/test/deployments/foo" && m == "GET":
responseDeployment := &appsv1.Deployment{}
responseDeployment.Name = "foo"
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)

View File

@ -18,7 +18,7 @@ package rollout
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"
@ -51,7 +51,7 @@ func TestRolloutPause(t *testing.T) {
case p == "/namespaces/test/deployments/nginx-deployment" && (m == "GET" || m == "PATCH"):
responseDeployment := &appsv1.Deployment{}
responseDeployment.Name = deploymentName
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)

View File

@ -18,7 +18,7 @@ package rollout
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -50,7 +50,7 @@ func TestRolloutRestartOne(t *testing.T) {
case p == "/namespaces/test/deployments/nginx-deployment" && (m == "GET" || m == "PATCH"):
responseDeployment := &appsv1.Deployment{}
responseDeployment.Name = deploymentName
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -88,7 +88,7 @@ func TestRolloutRestartSelectorNone(t *testing.T) {
case p == "/namespaces/test/deployments" && m == "GET" && q.Get("labelSelector") == labelSelector:
// Return an empty list
responseDeployments := &appsv1.DeploymentList{}
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployments))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployments))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@ -135,7 +135,7 @@ func TestRolloutRestartSelectorMany(t *testing.T) {
// Return the list of 2 deployments
responseDeployments := &appsv1.DeploymentList{}
responseDeployments.Items = []appsv1.Deployment{firstDeployment, secondDeployment}
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployments))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, responseDeployments))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
case (p == "/namespaces/test/deployments/nginx-deployment-1" || p == "/namespaces/test/deployments/nginx-deployment-2") && m == "PATCH":
// Pick deployment based on path
@ -143,7 +143,7 @@ func TestRolloutRestartSelectorMany(t *testing.T) {
if strings.HasSuffix(p, "nginx-deployment-2") {
responseDeployment = secondDeployment
}
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, &responseDeployment))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, &responseDeployment))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)

View File

@ -18,7 +18,7 @@ package rollout
import (
"bytes"
"io/ioutil"
"io"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/watch"
@ -50,7 +50,7 @@ func TestRolloutStatus(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
dep := &appsv1.Deployment{}
dep.Name = deploymentName
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
}),
}
@ -106,7 +106,7 @@ func TestRolloutStatusWithSelector(t *testing.T) {
dep.Name = deploymentName
dep.Labels = make(map[string]string)
dep.Labels["app"] = "api"
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
}),
}
@ -163,7 +163,7 @@ func TestRolloutStatusWatchDisabled(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
dep := &appsv1.Deployment{}
dep.Name = deploymentName
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
}),
}
@ -218,7 +218,7 @@ func TestRolloutStatusWatchDisabledUnavailable(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
dep := &appsv1.Deployment{}
dep.Name = deploymentName
body := ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
}),
}

View File

@ -19,7 +19,7 @@ package run
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"reflect"
@ -180,7 +180,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
}
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte("{}"))),
Body: io.NopCloser(bytes.NewBuffer([]byte("{}"))),
}, nil
}),
}
@ -338,7 +338,7 @@ func TestGenerateService(t *testing.T) {
case test.expectPOST && m == "POST" && p == "/namespaces/test/services":
sawPOST = true
body := cmdtesting.ObjBody(codec, &test.service)
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@ -579,7 +579,7 @@ func TestExpose(t *testing.T) {
body := cmdtesting.ObjBody(codec, pod)
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
case m == "POST" && p == "/namespaces/test/services":
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,7 @@ package set
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -498,7 +498,7 @@ func TestSetEnvRemote(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}
@ -690,7 +690,7 @@ func TestSetEnvFromResource(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}
@ -798,7 +798,7 @@ func TestSetEnvRemoteWithSpecificContainers(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}

View File

@ -18,7 +18,7 @@ package set
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -636,7 +636,7 @@ func TestSetImageRemote(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}
@ -748,7 +748,7 @@ func TestSetImageRemoteWithSpecificContainers(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}

View File

@ -18,7 +18,7 @@ package set
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -482,7 +482,7 @@ func TestSetResourcesRemote(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}
@ -588,7 +588,7 @@ func TestSetResourcesRemoteWithSpecificContainers(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}

View File

@ -19,7 +19,6 @@ package set
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"testing"
@ -333,7 +332,7 @@ func TestSetServiceAccountRemote(t *testing.T) {
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(stream)
bytes, err := io.ReadAll(stream)
if err != nil {
return nil, err
}

View File

@ -17,7 +17,7 @@ limitations under the License.
package taint
import (
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
@ -263,7 +263,7 @@ func TestTaint(t *testing.T) {
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, oldNode)}, nil
case m.isFor("PATCH", "/nodes/node-name"):
tainted = true
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("%s: unexpected error: %v", test.description, err)
}
@ -289,7 +289,7 @@ func TestTaint(t *testing.T) {
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, newNode)}, nil
case m.isFor("PUT", "/nodes/node-name"):
tainted = true
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("%s: unexpected error: %v", test.description, err)
}

View File

@ -19,7 +19,6 @@ package testing
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -428,7 +427,7 @@ type TestFactory struct {
func NewTestFactory() *TestFactory {
// specify an optionalClientConfig to explicitly use in testing
// to avoid polluting an existing user config.
tmpFile, err := ioutil.TempFile(os.TempDir(), "cmdtests_temp")
tmpFile, err := os.CreateTemp(os.TempDir(), "cmdtests_temp")
if err != nil {
panic(fmt.Sprintf("unable to create a fake client config: %v", err))
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"testing"
@ -55,15 +54,15 @@ func DefaultClientConfig() *restclient.Config {
}
func ObjBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj))))
return io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj))))
}
func BytesBody(bodyBytes []byte) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader(bodyBytes))
return io.NopCloser(bytes.NewReader(bodyBytes))
}
func StringBody(body string) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(body)))
return io.NopCloser(bytes.NewReader([]byte(body)))
}
func TestData() (*corev1.PodList, *corev1.ServiceList, *corev1.ReplicationControllerList) {

View File

@ -19,7 +19,7 @@ package top
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
@ -57,9 +57,9 @@ func TestTopNodeAllMetricsFrom(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/api":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
case p == expectedNodePath && m == "GET":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, nodes)}, nil
default:
@ -124,9 +124,9 @@ func TestTopNodeWithNameMetricsFrom(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/api":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
case p == expectedNodePath && m == "GET":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNode)}, nil
default:
@ -201,9 +201,9 @@ func TestTopNodeWithLabelSelectorMetricsFrom(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m, _ := req.URL.Path, req.Method, req.URL.RawQuery; {
case p == "/api":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
case p == expectedNodePath && m == "GET":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
default:
@ -278,9 +278,9 @@ func TestTopNodeWithSortByCpuMetricsFrom(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/api":
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
case p == expectedNodePath && m == "GET":
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
default:
@ -364,9 +364,9 @@ func TestTopNodeWithSortByMemoryMetricsFrom(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/api":
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
case p == expectedNodePath && m == "GET":
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
default:

View File

@ -18,7 +18,7 @@ package top
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/url"
"reflect"
@ -215,9 +215,9 @@ func TestTopPod(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p := req.URL.Path; {
case p == "/api":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
default:
t.Fatalf("%s: unexpected request: %#v\nGot URL: %#v",
testCase.name, req, req.URL)
@ -346,9 +346,9 @@ func TestTopPodNoResourcesFound(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p := req.URL.Path; {
case p == "/api":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apibody)))}, nil
case p == "/apis":
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: io.NopCloser(bytes.NewReader([]byte(apisbodyWithMetrics)))}, nil
case p == "/api/v1/namespaces/"+testNS+"/pods":
// Top Pod calls this endpoint to check if there are pods whenever it gets no metrics,
// so we need to return no pods for this test scenario

View File

@ -20,7 +20,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"time"
"testing"
@ -50,7 +49,7 @@ func marshallBody(metrics interface{}) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
return ioutil.NopCloser(bytes.NewReader(result)), nil
return io.NopCloser(bytes.NewReader(result)), nil
}
func testNodeV1beta1MetricsData() (*metricsv1beta1api.NodeMetricsList, *v1.NodeList) {

View File

@ -19,7 +19,6 @@ package editor
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -156,7 +155,7 @@ func (e Editor) LaunchTempFile(prefix, suffix string, r io.Reader) ([]byte, stri
if err := e.Launch(path); err != nil {
return nil, path, err
}
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
return bytes, path, err
}

View File

@ -18,7 +18,6 @@ package editor
import (
"bytes"
"io/ioutil"
"os"
"reflect"
"strings"
@ -51,7 +50,7 @@ func TestEditor(t *testing.T) {
t.Fatalf("no temp file: %s", path)
}
defer os.Remove(path)
if disk, err := ioutil.ReadFile(path); err != nil || !bytes.Equal(contents, disk) {
if disk, err := os.ReadFile(path); err != nil || !bytes.Equal(contents, disk) {
t.Errorf("unexpected file on disk: %v %s", err, string(disk))
}
if !bytes.Equal(contents, []byte(testStr)) {

View File

@ -19,7 +19,6 @@ package util
import (
goerrors "errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
@ -462,7 +461,7 @@ func testCheckError(t *testing.T, tests []checkErrTestCase) {
func TestDumpReaderToFile(t *testing.T) {
testString := "TEST STRING"
tempFile, err := ioutil.TempFile(os.TempDir(), "hlpers_test_dump_")
tempFile, err := os.CreateTemp(os.TempDir(), "hlpers_test_dump_")
if err != nil {
t.Errorf("unexpected error setting up a temporary file %v", err)
}
@ -477,7 +476,7 @@ func TestDumpReaderToFile(t *testing.T) {
if err != nil {
t.Errorf("error in DumpReaderToFile: %v", err)
}
data, err := ioutil.ReadFile(tempFile.Name())
data, err := os.ReadFile(tempFile.Name())
if err != nil {
t.Errorf("error when reading %s: %v", tempFile.Name(), err)
}

View File

@ -17,7 +17,7 @@ limitations under the License.
package wait
import (
"io/ioutil"
"io"
"strings"
"testing"
"time"
@ -963,7 +963,7 @@ func TestWaitForCondition(t *testing.T) {
Timeout: test.timeout,
Printer: printers.NewDiscardingPrinter(),
ConditionFn: ConditionalWait{conditionName: "the-condition", conditionStatus: "status-value", errOut: ioutil.Discard}.IsConditionMet,
ConditionFn: ConditionalWait{conditionName: "the-condition", conditionStatus: "status-value", errOut: io.Discard}.IsConditionMet,
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
}
err := o.RunWait()
@ -1181,7 +1181,7 @@ func TestWaitForDifferentJSONPathExpression(t *testing.T) {
ConditionFn: JSONPathWait{
jsonPathCondition: test.jsonPathCond,
jsonPathParser: j,
errOut: ioutil.Discard}.IsJSONPathConditionMet,
errOut: io.Discard}.IsJSONPathConditionMet,
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
}
@ -1444,7 +1444,7 @@ func TestWaitForJSONPathCondition(t *testing.T) {
Printer: printers.NewDiscardingPrinter(),
ConditionFn: JSONPathWait{
jsonPathCondition: test.jsonPathCond,
jsonPathParser: j, errOut: ioutil.Discard}.IsJSONPathConditionMet,
jsonPathParser: j, errOut: io.Discard}.IsJSONPathConditionMet,
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
}

View File

@ -18,7 +18,7 @@ package proxy
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@ -361,12 +361,12 @@ func TestFileServing(t *testing.T) {
fname = "test.txt"
data = "This is test data"
)
dir, err := ioutil.TempDir("", "data")
dir, err := os.MkdirTemp("", "data")
if err != nil {
t.Fatalf("error creating tmp dir: %v", err)
}
defer os.RemoveAll(dir)
if err := ioutil.WriteFile(filepath.Join(dir, fname), []byte(data), 0755); err != nil {
if err := os.WriteFile(filepath.Join(dir, fname), []byte(data), 0755); err != nil {
t.Fatalf("error writing tmp file: %v", err)
}
@ -385,7 +385,7 @@ func TestFileServing(t *testing.T) {
if res.StatusCode != http.StatusOK {
t.Errorf("res.StatusCode = %d; want %d", res.StatusCode, http.StatusOK)
}
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error reading resp body: %v", err)
}
@ -402,7 +402,7 @@ func newProxy(target *url.URL) http.Handler {
func TestAPIRequests(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@ -487,7 +487,7 @@ func TestPathHandling(t *testing.T) {
if err != nil {
t.Fatalf("%#v: %v", tt, err)
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
r.Body.Close()
if err != nil {
t.Fatalf("%#v: %v", tt, err)

View File

@ -19,7 +19,7 @@ package completion
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"strings"
"time"
@ -169,7 +169,7 @@ func CompGetContainers(f cmdutil.Factory, cmd *cobra.Command, podName string, to
// which begin with `toComplete`.
func CompGetFromTemplate(template *string, f cmdutil.Factory, namespace string, cmd *cobra.Command, args []string, toComplete string) []string {
buf := new(bytes.Buffer)
streams := genericclioptions.IOStreams{In: os.Stdin, Out: buf, ErrOut: ioutil.Discard}
streams := genericclioptions.IOStreams{In: os.Stdin, Out: buf, ErrOut: io.Discard}
o := get.NewGetOptions("kubectl", streams)
// Get the list of names of the specified resource
@ -259,7 +259,7 @@ func ListUsersInConfig(toComplete string) []string {
// compGetResourceList returns the list of api resources which begin with `toComplete`.
func compGetResourceList(restClientGetter genericclioptions.RESTClientGetter, cmd *cobra.Command, toComplete string) []string {
buf := new(bytes.Buffer)
streams := genericclioptions.IOStreams{In: os.Stdin, Out: buf, ErrOut: ioutil.Discard}
streams := genericclioptions.IOStreams{In: os.Stdin, Out: buf, ErrOut: io.Discard}
o := apiresources.NewAPIResourceOptions(streams)
o.Complete(restClientGetter, cmd, nil)