mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #111572 from inosato/remove-ioutil-from-kubectl
Remove ioutil from kubectl
This commit is contained in:
commit
c98bde46c5
@ -18,7 +18,7 @@ package annotate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -533,7 +533,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
|
|||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
Body: ioutil.NopCloser(bytes.NewBufferString(
|
Body: io.NopCloser(bytes.NewBufferString(
|
||||||
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"10"}}`,
|
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"10"}}`,
|
||||||
))}, nil
|
))}, nil
|
||||||
default:
|
default:
|
||||||
@ -543,7 +543,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
|
|||||||
case "PATCH":
|
case "PATCH":
|
||||||
switch req.URL.Path {
|
switch req.URL.Path {
|
||||||
case "/namespaces/test/pods/foo":
|
case "/namespaces/test/pods/foo":
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -553,7 +553,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
|
|||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
Body: ioutil.NopCloser(bytes.NewBufferString(
|
Body: io.NopCloser(bytes.NewBufferString(
|
||||||
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"11"}}`,
|
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"11"}}`,
|
||||||
))}, nil
|
))}, nil
|
||||||
default:
|
default:
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -232,7 +231,7 @@ func readBytesFromFile(t *testing.T, filename string) []byte {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(file)
|
data, err := io.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -398,9 +397,9 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
|
|||||||
|
|
||||||
switch p {
|
switch p {
|
||||||
case pathCM + "/test0":
|
case pathCM + "/test0":
|
||||||
body = ioutil.NopCloser(bytes.NewReader(configMapList[0]))
|
body = io.NopCloser(bytes.NewReader(configMapList[0]))
|
||||||
case pathCM + "/test1":
|
case pathCM + "/test1":
|
||||||
body = ioutil.NopCloser(bytes.NewReader(configMapList[1]))
|
body = io.NopCloser(bytes.NewReader(configMapList[1]))
|
||||||
default:
|
default:
|
||||||
t.Errorf("unexpected request to %s", p)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == "/namespaces/test/replicationcontrollers" && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == "/namespaces/test/replicationcontrollers/no-match" && m == "GET":
|
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
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
case p == pathRC && m == "PATCH":
|
||||||
validatePatchApplication(t, req, types.StrategicMergePatchType)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
case p == pathRC && m == "PATCH":
|
||||||
validatePatchApplication(t, req, types.StrategicMergePatchType)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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.
|
// During retry loop for patch fetch is performed.
|
||||||
// keep returning the unchanged data
|
// keep returning the unchanged data
|
||||||
if patches < targetPatches {
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,7 +1058,7 @@ func TestApplyCSAMigration(t *testing.T) {
|
|||||||
case 0:
|
case 0:
|
||||||
// initial apply.
|
// initial apply.
|
||||||
// Just return the same object but with managed fields
|
// 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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case 1:
|
case 1:
|
||||||
// Second apply should include only last apply annotation unmodified
|
// 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
|
// just return the same object unmodified. It is not so important
|
||||||
// for this test for the last-applied to appear in new field
|
// for this test for the last-applied to appear in new field
|
||||||
// manager response, only that the client asks the server to do it
|
// 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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case 2, 3:
|
case 2, 3:
|
||||||
// Before the last apply we have formed our JSONPAtch so it
|
// Before the last apply we have formed our JSONPAtch so it
|
||||||
// should reply now with the upgraded object
|
// 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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
require.Fail(t, "sent more apply requests than expected")
|
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
|
// 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.NoError(t, err)
|
||||||
require.Equal(t, expectedPatch, body)
|
require.Equal(t, expectedPatch, body)
|
||||||
|
|
||||||
switch patches {
|
switch patches {
|
||||||
case targetPatches - 1:
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
// Return conflict until the client has retried enough times
|
// 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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
case p == pathRC && m == "PATCH":
|
||||||
validatePatchApplication(t, req, types.StrategicMergePatchType)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
case p == pathRC && m == "GET":
|
||||||
getCount++
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
case p == pathRC && m == "PATCH":
|
||||||
if firstPatch {
|
if firstPatch {
|
||||||
firstPatch = false
|
firstPatch = false
|
||||||
statusErr := apierrors.NewConflict(schema.GroupResource{Group: "", Resource: "rc"}, "test-rc", fmt.Errorf("the object has been modified. Please apply at first"))
|
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)
|
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
|
return &http.Response{StatusCode: http.StatusConflict, Header: cmdtesting.DefaultHeader(), Body: bodyErr}, nil
|
||||||
}
|
}
|
||||||
retry = true
|
retry = true
|
||||||
validatePatchApplication(t, req, types.StrategicMergePatchType)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
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":
|
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":
|
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
|
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
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":
|
case p == pathNameRC && m == "GET":
|
||||||
if body == nil {
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "POST":
|
case p == pathRC && m == "POST":
|
||||||
body, _ = ioutil.ReadAll(req.Body)
|
body, _ = io.ReadAll(req.Body)
|
||||||
verifyPost = true
|
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
|
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
case p == pathRC && m == "PATCH":
|
||||||
validatePatchApplication(t, req, types.StrategicMergePatchType)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == pathSVC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodySVC}, nil
|
||||||
case p == pathSVC && m == "PATCH":
|
case p == pathSVC && m == "PATCH":
|
||||||
validatePatchApplication(t, req, types.StrategicMergePatchType)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodySVC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == deploymentPath && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
case p == deploymentPath && m == "PATCH":
|
case p == deploymentPath && m == "PATCH":
|
||||||
patch, err := ioutil.ReadAll(req.Body)
|
patch, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1524,7 +1523,7 @@ func TestApplyNULLPreservation(t *testing.T) {
|
|||||||
// The real API server would had returned the patched object but Kubectl
|
// The real API server would had returned the patched object but Kubectl
|
||||||
// is ignoring the actual return object.
|
// is ignoring the actual return object.
|
||||||
// TODO: Make this match actual server behavior by returning the patched 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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == path && m == "GET":
|
case p == path && m == "GET":
|
||||||
body := ioutil.NopCloser(bytes.NewReader(curr))
|
body := io.NopCloser(bytes.NewReader(curr))
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
@ -1584,7 +1583,7 @@ func TestUnstructuredApply(t *testing.T) {
|
|||||||
validatePatchApplication(t, req, types.MergePatchType)
|
validatePatchApplication(t, req, types.MergePatchType)
|
||||||
verifiedPatch = true
|
verifiedPatch = true
|
||||||
|
|
||||||
body := ioutil.NopCloser(bytes.NewReader(curr))
|
body := io.NopCloser(bytes.NewReader(curr))
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
@ -1640,7 +1639,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == path && m == "GET":
|
case p == path && m == "GET":
|
||||||
body := ioutil.NopCloser(bytes.NewReader(serversideData))
|
body := io.NopCloser(bytes.NewReader(serversideData))
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
@ -1648,7 +1647,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
|
|||||||
case p == path && m == "PATCH":
|
case p == path && m == "PATCH":
|
||||||
// In idempotent updates, kubectl will resolve to an empty patch and not send anything to the server
|
// 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.
|
// 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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1742,16 +1741,16 @@ func TestRunApplySetLastApplied(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == noAnnotationPath && m == "GET":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == noExistPath && m == "GET":
|
case p == noExistPath && m == "GET":
|
||||||
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.Pod{})}, nil
|
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.Pod{})}, nil
|
||||||
case p == pathRC && m == "PATCH":
|
case p == pathRC && m == "PATCH":
|
||||||
checkPatchString(t, req)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
case p == "/api/v1/namespaces/test" && m == "GET":
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.Namespace{})}, nil
|
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) {
|
func checkPatchString(t *testing.T, req *http.Request) {
|
||||||
checkString := string(readBytesFromFile(t, filenameRCPatchTest))
|
checkString := string(readBytesFromFile(t, filenameRCPatchTest))
|
||||||
patch, err := ioutil.ReadAll(req.Body)
|
patch, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1837,7 +1836,7 @@ func TestForceApply(t *testing.T) {
|
|||||||
case strings.HasSuffix(p, pathRC) && m == "GET":
|
case strings.HasSuffix(p, pathRC) && m == "GET":
|
||||||
if deleted {
|
if deleted {
|
||||||
counts["getNotFound"]++
|
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"]++
|
counts["getOk"]++
|
||||||
var bodyRC io.ReadCloser
|
var bodyRC io.ReadCloser
|
||||||
@ -1848,9 +1847,9 @@ func TestForceApply(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
bodyRC = ioutil.NopCloser(bytes.NewReader(rcBytes))
|
bodyRC = io.NopCloser(bytes.NewReader(rcBytes))
|
||||||
} else {
|
} 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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case strings.HasSuffix(p, pathRCList) && m == "GET":
|
case strings.HasSuffix(p, pathRCList) && m == "GET":
|
||||||
@ -1867,14 +1866,14 @@ func TestForceApply(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRCList}, nil
|
||||||
case strings.HasSuffix(p, pathRC) && m == "PATCH":
|
case strings.HasSuffix(p, pathRC) && m == "PATCH":
|
||||||
counts["patch"]++
|
counts["patch"]++
|
||||||
if counts["patch"] <= 6 {
|
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"))
|
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)
|
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
|
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)
|
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":
|
case strings.HasSuffix(p, pathRC) && m == "DELETE":
|
||||||
counts["delete"]++
|
counts["delete"]++
|
||||||
deleted = true
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case strings.HasSuffix(p, pathRC) && m == "PUT":
|
case strings.HasSuffix(p, pathRC) && m == "PUT":
|
||||||
counts["put"]++
|
counts["put"]++
|
||||||
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
|
bodyRC := io.NopCloser(bytes.NewReader(currentRC))
|
||||||
isScaledDownToZero = true
|
isScaledDownToZero = true
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
case strings.HasSuffix(p, pathRCList) && m == "POST":
|
case strings.HasSuffix(p, pathRCList) && m == "POST":
|
||||||
counts["post"]++
|
counts["post"]++
|
||||||
deleted = false
|
deleted = false
|
||||||
isScaledDownToZero = 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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -154,7 +153,7 @@ func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if o.Quiet {
|
if o.Quiet {
|
||||||
o.Out = ioutil.Discard
|
o.Out = io.Discard
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
|
@ -19,7 +19,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -122,8 +122,8 @@ func TestRunAccessCheck(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
test.o.Out = ioutil.Discard
|
test.o.Out = io.Discard
|
||||||
test.o.ErrOut = ioutil.Discard
|
test.o.ErrOut = io.Discard
|
||||||
|
|
||||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||||
defer tf.Cleanup()
|
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)
|
t.Errorf("%s: expected %v, got %v", test.name, expectPath, req.URL.Path)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
bodyBits, err := ioutil.ReadAll(req.Body)
|
bodyBits, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: %v", test.name, err)
|
t.Errorf("%s: %v", test.name, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@ -154,7 +154,7 @@ func TestRunAccessCheck(t *testing.T) {
|
|||||||
|
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
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),
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch req.URL.Path {
|
switch req.URL.Path {
|
||||||
case "/apis/authorization.k8s.io/v1/selfsubjectrulesreviews":
|
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
|
return &http.Response{StatusCode: http.StatusOK, Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
|
@ -19,7 +19,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ func TestWhoAmIRun(t *testing.T) {
|
|||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
|
||||||
test.o.Out = &b
|
test.o.Out = &b
|
||||||
test.o.ErrOut = ioutil.Discard
|
test.o.ErrOut = io.Discard
|
||||||
|
|
||||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||||
defer tf.Cleanup()
|
defer tf.Cleanup()
|
||||||
|
@ -18,7 +18,7 @@ package certificates
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -193,7 +193,7 @@ func TestCertificates(t *testing.T) {
|
|||||||
actions = append(actions, req.Method+" "+req.URL.Path)
|
actions = append(actions, req.Method+" "+req.URL.Path)
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case tc.nov1 && strings.HasPrefix(p, "/apis/certificates.k8s.io/v1/"):
|
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:
|
case p == "/apis/certificates.k8s.io/v1/certificatesigningrequests/missing" && m == http.MethodGet:
|
||||||
return &http.Response{StatusCode: http.StatusNotFound}, nil
|
return &http.Response{StatusCode: http.StatusNotFound}, nil
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package clusterinfo
|
package clusterinfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -57,7 +56,7 @@ func TestSetupOutputWriterNoOp(t *testing.T) {
|
|||||||
func TestSetupOutputWriterFile(t *testing.T) {
|
func TestSetupOutputWriterFile(t *testing.T) {
|
||||||
file := "output"
|
file := "output"
|
||||||
extension := ".json"
|
extension := ".json"
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "out")
|
dir, err := os.MkdirTemp(os.TempDir(), "out")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -75,7 +74,7 @@ func TestSetupOutputWriterFile(t *testing.T) {
|
|||||||
output := "some data here"
|
output := "some data here"
|
||||||
writer.Write([]byte(output))
|
writer.Write([]byte(output))
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(fullPath)
|
data, err := os.ReadFile(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -178,7 +177,7 @@ func (h *testPluginHandler) Lookup(filename string) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins, err := ioutil.ReadDir(h.pluginsDirectory)
|
plugins, err := os.ReadDir(h.pluginsDirectory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.err = err
|
h.err = err
|
||||||
return "", false
|
return "", false
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -261,10 +260,10 @@ func TestAdditionalAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmbedClientCert(t *testing.T) {
|
func TestEmbedClientCert(t *testing.T) {
|
||||||
fakeCertFile, _ := ioutil.TempFile(os.TempDir(), "")
|
fakeCertFile, _ := os.CreateTemp(os.TempDir(), "")
|
||||||
defer os.Remove(fakeCertFile.Name())
|
defer os.Remove(fakeCertFile.Name())
|
||||||
fakeData := []byte("fake-data")
|
fakeData := []byte("fake-data")
|
||||||
ioutil.WriteFile(fakeCertFile.Name(), fakeData, 0600)
|
os.WriteFile(fakeCertFile.Name(), fakeData, 0600)
|
||||||
expectedConfig := newRedFederalCowHammerConfig()
|
expectedConfig := newRedFederalCowHammerConfig()
|
||||||
authInfo := clientcmdapi.NewAuthInfo()
|
authInfo := clientcmdapi.NewAuthInfo()
|
||||||
authInfo.ClientCertificateData = fakeData
|
authInfo.ClientCertificateData = fakeData
|
||||||
@ -280,10 +279,10 @@ func TestEmbedClientCert(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmbedClientKey(t *testing.T) {
|
func TestEmbedClientKey(t *testing.T) {
|
||||||
fakeKeyFile, _ := ioutil.TempFile(os.TempDir(), "")
|
fakeKeyFile, _ := os.CreateTemp(os.TempDir(), "")
|
||||||
defer os.Remove(fakeKeyFile.Name())
|
defer os.Remove(fakeKeyFile.Name())
|
||||||
fakeData := []byte("fake-data")
|
fakeData := []byte("fake-data")
|
||||||
ioutil.WriteFile(fakeKeyFile.Name(), fakeData, 0600)
|
os.WriteFile(fakeKeyFile.Name(), fakeData, 0600)
|
||||||
expectedConfig := newRedFederalCowHammerConfig()
|
expectedConfig := newRedFederalCowHammerConfig()
|
||||||
authInfo := clientcmdapi.NewAuthInfo()
|
authInfo := clientcmdapi.NewAuthInfo()
|
||||||
authInfo.ClientKeyData = fakeData
|
authInfo.ClientKeyData = fakeData
|
||||||
@ -326,7 +325,7 @@ func TestEmbedNoKeyOrCertDisallowed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyTokenAndCertAllowed(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())
|
defer os.Remove(fakeCertFile.Name())
|
||||||
expectedConfig := newRedFederalCowHammerConfig()
|
expectedConfig := newRedFederalCowHammerConfig()
|
||||||
authInfo := clientcmdapi.NewAuthInfo()
|
authInfo := clientcmdapi.NewAuthInfo()
|
||||||
@ -569,7 +568,7 @@ func TestUnsetBytes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCAClearsInsecure(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())
|
defer os.Remove(fakeCAFile.Name())
|
||||||
clusterInfoWithInsecure := clientcmdapi.NewCluster()
|
clusterInfoWithInsecure := clientcmdapi.NewCluster()
|
||||||
clusterInfoWithInsecure.InsecureSkipTLSVerify = true
|
clusterInfoWithInsecure.InsecureSkipTLSVerify = true
|
||||||
@ -638,10 +637,10 @@ func TestInsecureClearsCA(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCADataClearsCA(t *testing.T) {
|
func TestCADataClearsCA(t *testing.T) {
|
||||||
fakeCAFile, _ := ioutil.TempFile(os.TempDir(), "")
|
fakeCAFile, _ := os.CreateTemp(os.TempDir(), "")
|
||||||
defer os.Remove(fakeCAFile.Name())
|
defer os.Remove(fakeCAFile.Name())
|
||||||
fakeData := []byte("cadata")
|
fakeData := []byte("cadata")
|
||||||
ioutil.WriteFile(fakeCAFile.Name(), fakeData, 0600)
|
os.WriteFile(fakeCAFile.Name(), fakeData, 0600)
|
||||||
|
|
||||||
clusterInfoWithCAData := clientcmdapi.NewCluster()
|
clusterInfoWithCAData := clientcmdapi.NewCluster()
|
||||||
clusterInfoWithCAData.CertificateAuthorityData = fakeData
|
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) {
|
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())
|
defer os.Remove(fakeKubeFile.Name())
|
||||||
err := clientcmd.WriteToFile(startingConfig, fakeKubeFile.Name())
|
err := clientcmd.WriteToFile(startingConfig, fakeKubeFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -57,7 +56,7 @@ func TestCurrentContextWithUnsetContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test currentContextTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -53,7 +52,7 @@ func TestDeleteCluster(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test deleteClusterTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -53,7 +52,7 @@ func TestDeleteContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test deleteContextTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ func TestGetClustersEmpty(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test getClustersTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -144,7 +143,7 @@ func TestGetContextsSelectOneOfTwo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test getContextsTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -103,7 +102,7 @@ func TestRenameToAlreadyExistingContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test renameContextTest) run(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())
|
defer os.Remove(fakeKubeFile.Name())
|
||||||
err := clientcmd.WriteToFile(test.initialConfig, fakeKubeFile.Name())
|
err := clientcmd.WriteToFile(test.initialConfig, fakeKubeFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ func (o *setClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluster)
|
|||||||
if o.certificateAuthority.Provided() {
|
if o.certificateAuthority.Provided() {
|
||||||
caPath := o.certificateAuthority.Value()
|
caPath := o.certificateAuthority.Value()
|
||||||
if o.embedCAData.Value() {
|
if o.embedCAData.Value() {
|
||||||
modifiedCluster.CertificateAuthorityData, _ = ioutil.ReadFile(caPath)
|
modifiedCluster.CertificateAuthorityData, _ = os.ReadFile(caPath)
|
||||||
modifiedCluster.InsecureSkipTLSVerify = false
|
modifiedCluster.InsecureSkipTLSVerify = false
|
||||||
modifiedCluster.CertificateAuthority = ""
|
modifiedCluster.CertificateAuthority = ""
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -183,7 +182,7 @@ func TestModifyClusterServerAndTLS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test setClusterTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ func TestModifyCurrentContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test setContextTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -221,7 +220,7 @@ func (o *setCredentialsOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut
|
|||||||
if o.clientCertificate.Provided() {
|
if o.clientCertificate.Provided() {
|
||||||
certPath := o.clientCertificate.Value()
|
certPath := o.clientCertificate.Value()
|
||||||
if o.embedCertData.Value() {
|
if o.embedCertData.Value() {
|
||||||
modifiedAuthInfo.ClientCertificateData, _ = ioutil.ReadFile(certPath)
|
modifiedAuthInfo.ClientCertificateData, _ = os.ReadFile(certPath)
|
||||||
modifiedAuthInfo.ClientCertificate = ""
|
modifiedAuthInfo.ClientCertificate = ""
|
||||||
} else {
|
} else {
|
||||||
certPath, _ = filepath.Abs(certPath)
|
certPath, _ = filepath.Abs(certPath)
|
||||||
@ -234,7 +233,7 @@ func (o *setCredentialsOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut
|
|||||||
if o.clientKey.Provided() {
|
if o.clientKey.Provided() {
|
||||||
keyPath := o.clientKey.Value()
|
keyPath := o.clientKey.Value()
|
||||||
if o.embedCertData.Value() {
|
if o.embedCertData.Value() {
|
||||||
modifiedAuthInfo.ClientKeyData, _ = ioutil.ReadFile(keyPath)
|
modifiedAuthInfo.ClientKeyData, _ = os.ReadFile(keyPath)
|
||||||
modifiedAuthInfo.ClientKey = ""
|
modifiedAuthInfo.ClientKey = ""
|
||||||
} else {
|
} else {
|
||||||
keyPath, _ = filepath.Abs(keyPath)
|
keyPath, _ = filepath.Abs(keyPath)
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -454,7 +453,7 @@ func TestSetCredentials(t *testing.T) {
|
|||||||
test.run(t)
|
test.run(t)
|
||||||
}
|
}
|
||||||
func (test setCredentialsTest) run(t *testing.T) {
|
func (test setCredentialsTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ func TestSetConfigCurrentContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test setConfigTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -106,7 +105,7 @@ func TestUnsetUnexistConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test unsetConfigTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -71,7 +70,7 @@ func TestUseContext(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test useContextTest) run(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -294,7 +293,7 @@ users:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test viewClusterTest) run(t *testing.T) {
|
func (test viewClusterTest) run(t *testing.T) {
|
||||||
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
|
fakeKubeFile, err := os.CreateTemp(os.TempDir(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"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
|
// listing the entire content of the current directory which could
|
||||||
// be too many choices for the user)
|
// be too many choices for the user)
|
||||||
if len(comps) > 0 && len(toComplete) > 0 {
|
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 {
|
for _, file := range files {
|
||||||
filename := file.Name()
|
filename := file.Name()
|
||||||
if strings.HasPrefix(filename, toComplete) {
|
if strings.HasPrefix(filename, toComplete) {
|
||||||
@ -423,7 +422,7 @@ func recursiveTar(srcDir, srcFile localPath, destDir, destFile remotePath, tw *t
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
files, err := ioutil.ReadDir(fpath)
|
files, err := os.ReadDir(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -309,15 +308,15 @@ func checkErr(t *testing.T, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTarUntar(t *testing.T) {
|
func TestTarUntar(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "input")
|
dir, err := os.MkdirTemp("", "input")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
dir = dir + "/"
|
dir = dir + "/"
|
||||||
|
|
||||||
dir2, err := ioutil.TempDir("", "output")
|
dir2, err := os.MkdirTemp("", "output")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
dir2 = dir2 + "/"
|
dir2 = dir2 + "/"
|
||||||
|
|
||||||
dir3, err := ioutil.TempDir("", "dir")
|
dir3, err := os.MkdirTemp("", "dir")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -450,11 +449,11 @@ func TestTarUntar(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTarUntarWrongPrefix(t *testing.T) {
|
func TestTarUntarWrongPrefix(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "input")
|
dir, err := os.MkdirTemp("", "input")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
dir = dir + "/"
|
dir = dir + "/"
|
||||||
|
|
||||||
dir2, err := ioutil.TempDir("", "output")
|
dir2, err := os.MkdirTemp("", "output")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -483,8 +482,8 @@ func TestTarUntarWrongPrefix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTarDestinationName(t *testing.T) {
|
func TestTarDestinationName(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "input")
|
dir, err := os.MkdirTemp(os.TempDir(), "input")
|
||||||
dir2, err2 := ioutil.TempDir(os.TempDir(), "output")
|
dir2, err2 := os.MkdirTemp(os.TempDir(), "output")
|
||||||
if err != nil || err2 != nil {
|
if err != nil || err2 != nil {
|
||||||
t.Errorf("unexpected error: %v | %v", err, err2)
|
t.Errorf("unexpected error: %v | %v", err, err2)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -554,7 +553,7 @@ func TestTarDestinationName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBadTar(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 {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v ", err)
|
t.Errorf("unexpected error: %v ", err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -614,7 +613,7 @@ func TestCopyToPod(t *testing.T) {
|
|||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: ns,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
responsePod := &v1.Pod{}
|
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)
|
cmd := NewCmdCp(tf, ioStreams)
|
||||||
|
|
||||||
srcFile, err := ioutil.TempDir("", "test")
|
srcFile, err := os.MkdirTemp("", "test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -685,7 +684,7 @@ func TestCopyToPodNoPreserve(t *testing.T) {
|
|||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: ns,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
responsePod := &v1.Pod{}
|
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)
|
cmd := NewCmdCp(tf, ioStreams)
|
||||||
|
|
||||||
srcFile, err := ioutil.TempDir("", "test")
|
srcFile, err := os.MkdirTemp("", "test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -769,7 +768,7 @@ func TestValidate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUntar(t *testing.T) {
|
func TestUntar(t *testing.T) {
|
||||||
testdir, err := ioutil.TempDir("", "test-untar")
|
testdir, err := os.MkdirTemp("", "test-untar")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(testdir)
|
defer os.RemoveAll(testdir)
|
||||||
t.Logf("Test base: %s", testdir)
|
t.Logf("Test base: %s", testdir)
|
||||||
@ -935,7 +934,7 @@ func TestUntar(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUntar_SingleFile(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)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(testdir)
|
defer os.RemoveAll(testdir)
|
||||||
|
|
||||||
@ -981,7 +980,7 @@ func createTmpFile(t *testing.T, filepath, data string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmpFileData(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)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(t, data, actual)
|
assert.EqualValues(t, data, actual)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package create
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -331,13 +330,13 @@ func handleConfigMapFromFileSources(configMap *corev1.ConfigMap, fileSources []s
|
|||||||
if strings.Contains(fileSource, "=") {
|
if strings.Contains(fileSource, "=") {
|
||||||
return fmt.Errorf("cannot give a key name for a directory path")
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("error listing files in %s: %v", filePath, err)
|
return fmt.Errorf("error listing files in %s: %v", filePath, err)
|
||||||
}
|
}
|
||||||
for _, item := range fileList {
|
for _, item := range fileList {
|
||||||
itemPath := path.Join(filePath, item.Name())
|
itemPath := path.Join(filePath, item.Name())
|
||||||
if item.Mode().IsRegular() {
|
if item.Type().IsRegular() {
|
||||||
keyName = item.Name()
|
keyName = item.Name()
|
||||||
err = addKeyFromFileToConfigMap(configMap, keyName, itemPath)
|
err = addKeyFromFileToConfigMap(configMap, keyName, itemPath)
|
||||||
if err != nil {
|
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
|
// 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.
|
// the value with the content of the given file path, or returns an error.
|
||||||
func addKeyFromFileToConfigMap(configMap *corev1.ConfigMap, keyName, filePath string) error {
|
func addKeyFromFileToConfigMap(configMap *corev1.ConfigMap, keyName, filePath string) error {
|
||||||
data, err := ioutil.ReadFile(filePath)
|
data, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package create
|
package create
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -465,7 +464,7 @@ func setupEnvFile(lines [][]string) func(*testing.T, *ConfigMapOptions) func() {
|
|||||||
files := []*os.File{}
|
files := []*os.File{}
|
||||||
filenames := configMapOptions.EnvFileSources
|
filenames := configMapOptions.EnvFileSources
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
file, err := ioutil.TempFile("", filename)
|
file, err := os.CreateTemp("", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
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() {
|
func setupBinaryFile(data []byte) func(*testing.T, *ConfigMapOptions) func() {
|
||||||
return func(t *testing.T, configMapOptions *ConfigMapOptions) func() {
|
return func(t *testing.T, configMapOptions *ConfigMapOptions) func() {
|
||||||
tmp, _ := ioutil.TempDir("", "")
|
tmp, _ := os.MkdirTemp("", "")
|
||||||
files := configMapOptions.FileSources
|
files := configMapOptions.FileSources
|
||||||
for i, file := range files {
|
for i, file := range files {
|
||||||
f := tmp + "/" + file
|
f := tmp + "/" + file
|
||||||
ioutil.WriteFile(f, data, 0644)
|
os.WriteFile(f, data, 0644)
|
||||||
configMapOptions.FileSources[i] = f
|
configMapOptions.FileSources[i] = f
|
||||||
}
|
}
|
||||||
return func() {
|
return func() {
|
||||||
|
@ -18,7 +18,7 @@ package create
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -45,7 +45,7 @@ func TestCreateDeployment(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func TestCreateDeploymentWithPort(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func TestCreateDeploymentWithReplicas(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ func TestCreateDeploymentNoImage(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
Body: io.NopCloser(bytes.NewBuffer([]byte(fakeDiscovery))),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package create
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func TestCreatePriorityClass(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(&bytes.Buffer{}),
|
Body: io.NopCloser(&bytes.Buffer{}),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package create
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -352,13 +351,13 @@ func handleSecretFromFileSources(secret *corev1.Secret, fileSources []string) er
|
|||||||
if strings.Contains(fileSource, "=") {
|
if strings.Contains(fileSource, "=") {
|
||||||
return fmt.Errorf("cannot give a key name for a directory path")
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("error listing files in %s: %v", filePath, err)
|
return fmt.Errorf("error listing files in %s: %v", filePath, err)
|
||||||
}
|
}
|
||||||
for _, item := range fileList {
|
for _, item := range fileList {
|
||||||
itemPath := path.Join(filePath, item.Name())
|
itemPath := path.Join(filePath, item.Name())
|
||||||
if item.Mode().IsRegular() {
|
if item.Type().IsRegular() {
|
||||||
keyName = item.Name()
|
keyName = item.Name()
|
||||||
if err := addKeyFromFileToSecret(secret, keyName, itemPath); err != nil {
|
if err := addKeyFromFileToSecret(secret, keyName, itemPath); err != nil {
|
||||||
return err
|
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
|
// 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.
|
// the value with the content of the given file path, or returns an error.
|
||||||
func addKeyFromFileToSecret(secret *corev1.Secret, keyName, filePath string) error {
|
func addKeyFromFileToSecret(secret *corev1.Secret, keyName, filePath string) error {
|
||||||
data, err := ioutil.ReadFile(filePath)
|
data, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package create
|
package create
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -540,7 +539,7 @@ func setupSecretEnvFile(lines [][]string) func(*testing.T, *CreateSecretOptions)
|
|||||||
files := []*os.File{}
|
files := []*os.File{}
|
||||||
filenames := secretOptions.EnvFileSources
|
filenames := secretOptions.EnvFileSources
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
file, err := ioutil.TempFile("", filename)
|
file, err := os.CreateTemp("", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
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() {
|
func setupSecretBinaryFile(data []byte) func(*testing.T, *CreateSecretOptions) func() {
|
||||||
return func(t *testing.T, secretOptions *CreateSecretOptions) func() {
|
return func(t *testing.T, secretOptions *CreateSecretOptions) func() {
|
||||||
tmp, _ := ioutil.TempDir("", "")
|
tmp, _ := os.MkdirTemp("", "")
|
||||||
files := secretOptions.FileSources
|
files := secretOptions.FileSources
|
||||||
for i, file := range files {
|
for i, file := range files {
|
||||||
f := tmp + "/" + file
|
f := tmp + "/" + file
|
||||||
ioutil.WriteFile(f, data, 0644)
|
os.WriteFile(f, data, 0644)
|
||||||
secretOptions.FileSources[i] = f
|
secretOptions.FileSources[i] = f
|
||||||
}
|
}
|
||||||
return func() {
|
return func() {
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
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.
|
// readFile just reads a file into a byte array.
|
||||||
func readFile(file string) ([]byte, error) {
|
func readFile(file string) ([]byte, error) {
|
||||||
b, err := ioutil.ReadFile(file)
|
b, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, fmt.Errorf("Cannot read file %v, %v", file, err)
|
return []byte{}, fmt.Errorf("Cannot read file %v, %v", file, err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package create
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -280,7 +280,7 @@ status:
|
|||||||
if req.URL.Path != test.expectRequestPath {
|
if req.URL.Path != test.expectRequestPath {
|
||||||
t.Fatalf("expected %q, got %q", test.expectRequestPath, req.URL.Path)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ status:
|
|||||||
|
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: code,
|
StatusCode: code,
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
|
Body: io.NopCloser(bytes.NewBuffer(body)),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package delete
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -104,7 +103,7 @@ func hasExpectedPropagationPolicy(body io.ReadCloser, policy *metav1.DeletionPro
|
|||||||
return body == nil && policy == nil
|
return body == nil && policy == nil
|
||||||
}
|
}
|
||||||
var parsedBody metav1.DeleteOptions
|
var parsedBody metav1.DeleteOptions
|
||||||
rawBody, _ := ioutil.ReadAll(body)
|
rawBody, _ := io.ReadAll(body)
|
||||||
json.Unmarshal(rawBody, &parsedBody)
|
json.Unmarshal(rawBody, &parsedBody)
|
||||||
if parsedBody.PropagationPolicy == nil {
|
if parsedBody.PropagationPolicy == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -19,7 +19,6 @@ package diff
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -286,7 +285,7 @@ type Directory struct {
|
|||||||
// CreateDirectory does create the actual disk directory, and return a
|
// CreateDirectory does create the actual disk directory, and return a
|
||||||
// new representation of it.
|
// new representation of it.
|
||||||
func CreateDirectory(prefix string) (*Directory, error) {
|
func CreateDirectory(prefix string) (*Directory, error) {
|
||||||
name, err := ioutil.TempDir("", prefix+"-")
|
name, err := os.MkdirTemp("", prefix+"-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package diff
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -134,7 +133,7 @@ func TestDiffVersion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ func TestDirectory(t *testing.T) {
|
|||||||
if !strings.HasPrefix(filepath.Base(dir.Name), "prefix") {
|
if !strings.HasPrefix(filepath.Base(dir.Name), "prefix") {
|
||||||
t.Fatalf(`Directory doesn't start with "prefix": %q`, dir.Name)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -172,7 +171,7 @@ func TestDirectory(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
entries, err = ioutil.ReadDir(dir.Name)
|
entries, err = os.ReadDir(dir.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -205,7 +204,7 @@ func TestDiffer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -214,7 +213,7 @@ func TestDiffer(t *testing.T) {
|
|||||||
t.Fatalf("File has %q, expected %q", string(fcontent), econtent)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -290,12 +289,12 @@ metadata:
|
|||||||
t.Fatal(err)
|
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 {
|
if string(actualFromContent) != tc.expectedFromContent {
|
||||||
t.Fatalf("File has %q, expected %q", 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 {
|
if string(actualToContent) != tc.expectedToContent {
|
||||||
t.Fatalf("File has %q, expected %q", string(actualToContent), tc.expectedToContent)
|
t.Fatalf("File has %q, expected %q", string(actualToContent), tc.expectedToContent)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package drain
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -182,7 +182,7 @@ func TestCordon(t *testing.T) {
|
|||||||
case m.isFor("PATCH", "/nodes/node2"):
|
case m.isFor("PATCH", "/nodes/node2"):
|
||||||
fallthrough
|
fallthrough
|
||||||
case m.isFor("PATCH", "/nodes/node"):
|
case m.isFor("PATCH", "/nodes/node"):
|
||||||
data, err := ioutil.ReadAll(req.Body)
|
data, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
||||||
}
|
}
|
||||||
@ -833,7 +833,7 @@ func TestDrain(t *testing.T) {
|
|||||||
case m.isFor("GET", "/replicationcontrollers"):
|
case m.isFor("GET", "/replicationcontrollers"):
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &corev1.ReplicationControllerList{Items: test.rcs})}, nil
|
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"):
|
case m.isFor("PATCH", "/nodes/node"):
|
||||||
data, err := ioutil.ReadAll(req.Body)
|
data, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
@ -98,20 +97,20 @@ func TestEdit(t *testing.T) {
|
|||||||
|
|
||||||
body := []byte{}
|
body := []byte{}
|
||||||
if req.Body != nil {
|
if req.Body != nil {
|
||||||
body, err = ioutil.ReadAll(req.Body)
|
body, err = io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s, step %d: %v", name, i, err)
|
t.Fatalf("%s, step %d: %v", name, i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile := filepath.Join("testdata", "testcase-"+name, step.Input)
|
inputFile := filepath.Join("testdata", "testcase-"+name, step.Input)
|
||||||
expectedInput, err := ioutil.ReadFile(inputFile)
|
expectedInput, err := os.ReadFile(inputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s, step %d: %v", name, i, err)
|
t.Fatalf("%s, step %d: %v", name, i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFile := filepath.Join("testdata", "testcase-"+name, step.Output)
|
outputFile := filepath.Join("testdata", "testcase-"+name, step.Output)
|
||||||
resultingOutput, err := ioutil.ReadFile(outputFile)
|
resultingOutput, err := os.ReadFile(outputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s, step %d: %v", name, i, err)
|
t.Fatalf("%s, step %d: %v", name, i, err)
|
||||||
}
|
}
|
||||||
@ -123,13 +122,13 @@ func TestEdit(t *testing.T) {
|
|||||||
if !bytes.Equal(body, expectedInput) {
|
if !bytes.Equal(body, expectedInput) {
|
||||||
if updateInputFixtures {
|
if updateInputFixtures {
|
||||||
// Convenience to allow recapturing the input and persisting it here
|
// 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 {
|
} else {
|
||||||
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
|
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)
|
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" {
|
if step.StepType != "request" {
|
||||||
t.Fatalf("%s, step %d: expected request step, got %s %s", name, i, req.Method, req.URL.Path)
|
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 !bytes.Equal(body, expectedInput) {
|
||||||
if updateInputFixtures {
|
if updateInputFixtures {
|
||||||
// Convenience to allow recapturing the input and persisting it here
|
// 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 {
|
} else {
|
||||||
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
|
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)
|
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
|
name = testcaseName
|
||||||
testcase = EditTestCase{}
|
testcase = EditTestCase{}
|
||||||
testcaseDir := filepath.Join("testdata", "testcase-"+name)
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("%s: %v", name, err)
|
t.Fatalf("%s: %v", name, err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -85,7 +85,7 @@ func main() {
|
|||||||
record = true
|
record = true
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
switch m, p := req.Method, req.URL.Path; {
|
switch m, p := req.Method, req.URL.Path; {
|
||||||
@ -94,14 +94,14 @@ func main() {
|
|||||||
panic("cannot post input with step already in progress")
|
panic("cannot post input with step already in progress")
|
||||||
}
|
}
|
||||||
filename := fmt.Sprintf("%d.original", len(tc.Steps))
|
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}
|
currentStep = &EditStep{StepType: "edit", Input: filename}
|
||||||
case m == "POST" && p == "/callback/out":
|
case m == "POST" && p == "/callback/out":
|
||||||
if currentStep == nil || currentStep.StepType != "edit" {
|
if currentStep == nil || currentStep.StepType != "edit" {
|
||||||
panic("cannot post output without posting input first")
|
panic("cannot post output without posting input first")
|
||||||
}
|
}
|
||||||
filename := fmt.Sprintf("%d.edited", len(tc.Steps))
|
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
|
currentStep.Output = filename
|
||||||
tc.Steps = append(tc.Steps, *currentStep)
|
tc.Steps = append(tc.Steps, *currentStep)
|
||||||
currentStep = nil
|
currentStep = nil
|
||||||
@ -120,7 +120,7 @@ func main() {
|
|||||||
checkErr(err)
|
checkErr(err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
bodyOut, err := ioutil.ReadAll(resp.Body)
|
bodyOut, err := io.ReadAll(resp.Body)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
for k, vs := range resp.Header {
|
for k, vs := range resp.Header {
|
||||||
@ -134,8 +134,8 @@ func main() {
|
|||||||
if record {
|
if record {
|
||||||
infile := fmt.Sprintf("%d.request", len(tc.Steps))
|
infile := fmt.Sprintf("%d.request", len(tc.Steps))
|
||||||
outfile := fmt.Sprintf("%d.response", len(tc.Steps))
|
outfile := fmt.Sprintf("%d.response", len(tc.Steps))
|
||||||
checkErr(ioutil.WriteFile(infile, tryIndent(body), os.FileMode(0755)))
|
checkErr(os.WriteFile(infile, tryIndent(body), os.FileMode(0755)))
|
||||||
checkErr(ioutil.WriteFile(outfile, tryIndent(bodyOut), os.FileMode(0755)))
|
checkErr(os.WriteFile(outfile, tryIndent(bodyOut), os.FileMode(0755)))
|
||||||
tc.Steps = append(tc.Steps, EditStep{
|
tc.Steps = append(tc.Steps, EditStep{
|
||||||
StepType: "request",
|
StepType: "request",
|
||||||
Input: infile,
|
Input: infile,
|
||||||
@ -150,7 +150,7 @@ func main() {
|
|||||||
|
|
||||||
tcData, err := yaml.Marshal(tc)
|
tcData, err := yaml.Marshal(tc)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
checkErr(ioutil.WriteFile("test.yaml", tcData, os.FileMode(0755)))
|
checkErr(os.WriteFile("test.yaml", tcData, os.FileMode(0755)))
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -373,7 +372,7 @@ func TestSetupTTY(t *testing.T) {
|
|||||||
stderr.Reset()
|
stderr.Reset()
|
||||||
o.TTY = true
|
o.TTY = true
|
||||||
|
|
||||||
overrideStdin := ioutil.NopCloser(&bytes.Buffer{})
|
overrideStdin := io.NopCloser(&bytes.Buffer{})
|
||||||
overrideStdout := &bytes.Buffer{}
|
overrideStdout := &bytes.Buffer{}
|
||||||
overrideStderr := &bytes.Buffer{}
|
overrideStderr := &bytes.Buffer{}
|
||||||
o.overrideStreams = func() (io.ReadCloser, io.Writer, io.Writer) {
|
o.overrideStreams = func() (io.ReadCloser, io.Writer, io.Writer) {
|
||||||
|
@ -19,7 +19,6 @@ package get
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -32,7 +31,7 @@ import (
|
|||||||
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
|
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
|
||||||
testObject := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -746,7 +745,7 @@ func TestGetEmptyTable(t *testing.T) {
|
|||||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||||
defer tf.Cleanup()
|
defer tf.Cleanup()
|
||||||
|
|
||||||
emptyTable := ioutil.NopCloser(bytes.NewBufferString(`{
|
emptyTable := io.NopCloser(bytes.NewBufferString(`{
|
||||||
"kind":"Table",
|
"kind":"Table",
|
||||||
"apiVersion":"meta.k8s.io/v1beta1",
|
"apiVersion":"meta.k8s.io/v1beta1",
|
||||||
"metadata":{
|
"metadata":{
|
||||||
@ -959,7 +958,7 @@ func TestGetSortedObjectsUnstructuredTable(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// t.Log(string(unstructuredBytes))
|
// t.Log(string(unstructuredBytes))
|
||||||
body := ioutil.NopCloser(bytes.NewReader(unstructuredBytes))
|
body := io.NopCloser(bytes.NewReader(unstructuredBytes))
|
||||||
|
|
||||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||||
defer tf.Cleanup()
|
defer tf.Cleanup()
|
||||||
@ -2844,7 +2843,7 @@ func watchBody(codec runtime.Codec, events []watch.Event) io.ReadCloser {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ioutil.NopCloser(buf)
|
return io.NopCloser(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
var podColumns = []metav1.TableColumnDefinition{
|
var podColumns = []metav1.TableColumnDefinition{
|
||||||
|
@ -19,7 +19,7 @@ package label
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -531,7 +531,7 @@ func TestLabelResourceVersion(t *testing.T) {
|
|||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
Body: ioutil.NopCloser(bytes.NewBufferString(
|
Body: io.NopCloser(bytes.NewBufferString(
|
||||||
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"10"}}`,
|
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"10"}}`,
|
||||||
))}, nil
|
))}, nil
|
||||||
default:
|
default:
|
||||||
@ -541,7 +541,7 @@ func TestLabelResourceVersion(t *testing.T) {
|
|||||||
case "PATCH":
|
case "PATCH":
|
||||||
switch req.URL.Path {
|
switch req.URL.Path {
|
||||||
case "/namespaces/test/pods/foo":
|
case "/namespaces/test/pods/foo":
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -551,7 +551,7 @@ func TestLabelResourceVersion(t *testing.T) {
|
|||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
Header: cmdtesting.DefaultHeader(),
|
||||||
Body: ioutil.NopCloser(bytes.NewBufferString(
|
Body: io.NopCloser(bytes.NewBufferString(
|
||||||
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"11"}}`,
|
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","resourceVersion":"11"}}`,
|
||||||
))}, nil
|
))}, nil
|
||||||
default:
|
default:
|
||||||
@ -602,7 +602,7 @@ func TestRunLabelMsg(t *testing.T) {
|
|||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
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"}}}`,
|
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","labels":{"existing":"abc"}}}`,
|
||||||
))}, nil
|
))}, nil
|
||||||
default:
|
default:
|
||||||
@ -615,7 +615,7 @@ func TestRunLabelMsg(t *testing.T) {
|
|||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: cmdtesting.DefaultHeader(),
|
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"}}}`,
|
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"foo","namespace":"test","labels":{"existing":"abc"}}}`,
|
||||||
))}, nil
|
))}, nil
|
||||||
default:
|
default:
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -839,12 +838,12 @@ type responseWrapperMock struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *responseWrapperMock) DoRaw(context.Context) ([]byte, error) {
|
func (r *responseWrapperMock) DoRaw(context.Context) ([]byte, error) {
|
||||||
data, _ := ioutil.ReadAll(r.data)
|
data, _ := io.ReadAll(r.data)
|
||||||
return data, r.err
|
return data, r.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *responseWrapperMock) Stream(context.Context) (io.ReadCloser, error) {
|
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 {
|
type logTestMock struct {
|
||||||
|
@ -18,7 +18,7 @@ package patch
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ func (o *PatchOptions) RunPatch() error {
|
|||||||
var patchBytes []byte
|
var patchBytes []byte
|
||||||
if len(o.PatchFile) > 0 {
|
if len(o.PatchFile) > 0 {
|
||||||
var err error
|
var err error
|
||||||
patchBytes, err = ioutil.ReadFile(o.PatchFile)
|
patchBytes, err = os.ReadFile(o.PatchFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to read patch file: %v", err)
|
return fmt.Errorf("unable to read patch file: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -166,7 +165,7 @@ func (o *PluginListOptions) ListPlugins() ([]string, []error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(dir)
|
files, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*os.PathError); ok {
|
if _, ok := err.(*os.PathError); ok {
|
||||||
fmt.Fprintf(o.ErrOut, "Unable to read directory %q from your PATH: %v. Skipping...\n", dir, err)
|
fmt.Fprintf(o.ErrOut, "Unable to read directory %q from your PATH: %v. Skipping...\n", dir, err)
|
||||||
|
@ -19,7 +19,7 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -83,8 +83,8 @@ func addPluginCommands(cmd *cobra.Command) {
|
|||||||
kubectl := cmd.Root()
|
kubectl := cmd.Root()
|
||||||
streams := genericclioptions.IOStreams{
|
streams := genericclioptions.IOStreams{
|
||||||
In: &bytes.Buffer{},
|
In: &bytes.Buffer{},
|
||||||
Out: ioutil.Discard,
|
Out: io.Discard,
|
||||||
ErrOut: ioutil.Discard,
|
ErrOut: io.Discard,
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &PluginListOptions{IOStreams: streams}
|
o := &PluginListOptions{IOStreams: streams}
|
||||||
|
@ -18,7 +18,6 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -29,11 +28,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPluginPathsAreUnaltered(t *testing.T) {
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -58,10 +57,10 @@ func TestPluginPathsAreUnaltered(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write at least one valid plugin file
|
// 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)
|
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)
|
t.Fatalf("unexpected error %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ func TestPluginPathsAreUnaltered(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginPathsAreValid(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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -107,7 +106,7 @@ func TestPluginPathsAreValid(t *testing.T) {
|
|||||||
pluginPaths: []string{tempDir},
|
pluginPaths: []string{tempDir},
|
||||||
verifier: newFakePluginPathVerifier(),
|
verifier: newFakePluginPathVerifier(),
|
||||||
pluginFile: func() (*os.File, error) {
|
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",
|
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},
|
pluginPaths: []string{tempDir, tempDir},
|
||||||
verifier: newFakePluginPathVerifier(),
|
verifier: newFakePluginPathVerifier(),
|
||||||
pluginFile: func() (*os.File, error) {
|
pluginFile: func() (*os.File, error) {
|
||||||
return ioutil.TempFile(tempDir, "kubectl-")
|
return os.CreateTemp(tempDir, "kubectl-")
|
||||||
},
|
},
|
||||||
expectOut: "The following compatible plugins are available:",
|
expectOut: "The following compatible plugins are available:",
|
||||||
},
|
},
|
||||||
@ -125,7 +124,7 @@ func TestPluginPathsAreValid(t *testing.T) {
|
|||||||
pluginPaths: []string{tempDir, "", " "},
|
pluginPaths: []string{tempDir, "", " "},
|
||||||
verifier: newFakePluginPathVerifier(),
|
verifier: newFakePluginPathVerifier(),
|
||||||
pluginFile: func() (*os.File, error) {
|
pluginFile: func() (*os.File, error) {
|
||||||
return ioutil.TempFile(tempDir, "kubectl-")
|
return os.CreateTemp(tempDir, "kubectl-")
|
||||||
},
|
},
|
||||||
expectOut: "The following compatible plugins are available:",
|
expectOut: "The following compatible plugins are available:",
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,6 @@ package replace
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -331,7 +330,7 @@ func (o *ReplaceOptions) forceReplace() error {
|
|||||||
stdinInUse := false
|
stdinInUse := false
|
||||||
for i, filename := range o.DeleteOptions.FilenameOptions.Filenames {
|
for i, filename := range o.DeleteOptions.FilenameOptions.Filenames {
|
||||||
if filename == "-" {
|
if filename == "-" {
|
||||||
tempDir, err := ioutil.TempDir("", "kubectl_replace_")
|
tempDir, err := os.MkdirTemp("", "kubectl_replace_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package rollout
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ func TestRolloutHistory(t *testing.T) {
|
|||||||
case p == "/namespaces/test/deployments/foo" && m == "GET":
|
case p == "/namespaces/test/deployments/foo" && m == "GET":
|
||||||
responseDeployment := &appsv1.Deployment{}
|
responseDeployment := &appsv1.Deployment{}
|
||||||
responseDeployment.Name = "foo"
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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":
|
case p == "/namespaces/test/deployments/foo" && m == "GET":
|
||||||
responseDeployment := &appsv1.Deployment{}
|
responseDeployment := &appsv1.Deployment{}
|
||||||
responseDeployment.Name = "foo"
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
case p == "/namespaces/test/deployments/bar" && m == "GET":
|
case p == "/namespaces/test/deployments/bar" && m == "GET":
|
||||||
responseDeployment := &appsv1.Deployment{}
|
responseDeployment := &appsv1.Deployment{}
|
||||||
responseDeployment.Name = "bar"
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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":
|
case p == "/namespaces/test/deployments/foo" && m == "GET":
|
||||||
responseDeployment := &appsv1.Deployment{}
|
responseDeployment := &appsv1.Deployment{}
|
||||||
responseDeployment.Name = "foo"
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
|
@ -18,7 +18,7 @@ package rollout
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ func TestRolloutPause(t *testing.T) {
|
|||||||
case p == "/namespaces/test/deployments/nginx-deployment" && (m == "GET" || m == "PATCH"):
|
case p == "/namespaces/test/deployments/nginx-deployment" && (m == "GET" || m == "PATCH"):
|
||||||
responseDeployment := &appsv1.Deployment{}
|
responseDeployment := &appsv1.Deployment{}
|
||||||
responseDeployment.Name = deploymentName
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
|
@ -18,7 +18,7 @@ package rollout
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -50,7 +50,7 @@ func TestRolloutRestartOne(t *testing.T) {
|
|||||||
case p == "/namespaces/test/deployments/nginx-deployment" && (m == "GET" || m == "PATCH"):
|
case p == "/namespaces/test/deployments/nginx-deployment" && (m == "GET" || m == "PATCH"):
|
||||||
responseDeployment := &appsv1.Deployment{}
|
responseDeployment := &appsv1.Deployment{}
|
||||||
responseDeployment.Name = deploymentName
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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:
|
case p == "/namespaces/test/deployments" && m == "GET" && q.Get("labelSelector") == labelSelector:
|
||||||
// Return an empty list
|
// Return an empty list
|
||||||
responseDeployments := &appsv1.DeploymentList{}
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
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
|
// Return the list of 2 deployments
|
||||||
responseDeployments := &appsv1.DeploymentList{}
|
responseDeployments := &appsv1.DeploymentList{}
|
||||||
responseDeployments.Items = []appsv1.Deployment{firstDeployment, secondDeployment}
|
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
|
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":
|
case (p == "/namespaces/test/deployments/nginx-deployment-1" || p == "/namespaces/test/deployments/nginx-deployment-2") && m == "PATCH":
|
||||||
// Pick deployment based on path
|
// Pick deployment based on path
|
||||||
@ -143,7 +143,7 @@ func TestRolloutRestartSelectorMany(t *testing.T) {
|
|||||||
if strings.HasSuffix(p, "nginx-deployment-2") {
|
if strings.HasSuffix(p, "nginx-deployment-2") {
|
||||||
responseDeployment = secondDeployment
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
|
@ -18,7 +18,7 @@ package rollout
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
@ -50,7 +50,7 @@ func TestRolloutStatus(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
dep := &appsv1.Deployment{}
|
dep := &appsv1.Deployment{}
|
||||||
dep.Name = deploymentName
|
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
|
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.Name = deploymentName
|
||||||
dep.Labels = make(map[string]string)
|
dep.Labels = make(map[string]string)
|
||||||
dep.Labels["app"] = "api"
|
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
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
dep := &appsv1.Deployment{}
|
dep := &appsv1.Deployment{}
|
||||||
dep.Name = deploymentName
|
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
|
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) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
dep := &appsv1.Deployment{}
|
dep := &appsv1.Deployment{}
|
||||||
dep.Name = deploymentName
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package run
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -180,7 +180,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte("{}"))),
|
Body: io.NopCloser(bytes.NewBuffer([]byte("{}"))),
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ func TestGenerateService(t *testing.T) {
|
|||||||
case test.expectPOST && m == "POST" && p == "/namespaces/test/services":
|
case test.expectPOST && m == "POST" && p == "/namespaces/test/services":
|
||||||
sawPOST = true
|
sawPOST = true
|
||||||
body := cmdtesting.ObjBody(codec, &test.service)
|
body := cmdtesting.ObjBody(codec, &test.service)
|
||||||
data, err := ioutil.ReadAll(req.Body)
|
data, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -579,7 +579,7 @@ func TestExpose(t *testing.T) {
|
|||||||
body := cmdtesting.ObjBody(codec, pod)
|
body := cmdtesting.ObjBody(codec, pod)
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
case m == "POST" && p == "/namespaces/test/services":
|
case m == "POST" && p == "/namespaces/test/services":
|
||||||
data, err := ioutil.ReadAll(req.Body)
|
data, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -498,7 +498,7 @@ func TestSetEnvRemote(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -690,7 +690,7 @@ func TestSetEnvFromResource(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -798,7 +798,7 @@ func TestSetEnvRemoteWithSpecificContainers(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -636,7 +636,7 @@ func TestSetImageRemote(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -748,7 +748,7 @@ func TestSetImageRemoteWithSpecificContainers(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -482,7 +482,7 @@ func TestSetResourcesRemote(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -588,7 +588,7 @@ func TestSetResourcesRemoteWithSpecificContainers(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package set
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -333,7 +332,7 @@ func TestSetServiceAccountRemote(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(stream)
|
bytes, err := io.ReadAll(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package taint
|
package taint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, oldNode)}, nil
|
||||||
case m.isFor("PATCH", "/nodes/node-name"):
|
case m.isFor("PATCH", "/nodes/node-name"):
|
||||||
tainted = true
|
tainted = true
|
||||||
data, err := ioutil.ReadAll(req.Body)
|
data, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
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
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, newNode)}, nil
|
||||||
case m.isFor("PUT", "/nodes/node-name"):
|
case m.isFor("PUT", "/nodes/node-name"):
|
||||||
tainted = true
|
tainted = true
|
||||||
data, err := ioutil.ReadAll(req.Body)
|
data, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package testing
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -428,7 +427,7 @@ type TestFactory struct {
|
|||||||
func NewTestFactory() *TestFactory {
|
func NewTestFactory() *TestFactory {
|
||||||
// specify an optionalClientConfig to explicitly use in testing
|
// specify an optionalClientConfig to explicitly use in testing
|
||||||
// to avoid polluting an existing user config.
|
// 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 {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("unable to create a fake client config: %v", err))
|
panic(fmt.Sprintf("unable to create a fake client config: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -55,15 +54,15 @@ func DefaultClientConfig() *restclient.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ObjBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
|
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 {
|
func BytesBody(bodyBytes []byte) io.ReadCloser {
|
||||||
return ioutil.NopCloser(bytes.NewReader(bodyBytes))
|
return io.NopCloser(bytes.NewReader(bodyBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func StringBody(body string) io.ReadCloser {
|
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) {
|
func TestData() (*corev1.PodList, *corev1.ServiceList, *corev1.ReplicationControllerList) {
|
||||||
|
@ -19,7 +19,7 @@ package top
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -57,9 +57,9 @@ func TestTopNodeAllMetricsFrom(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api":
|
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":
|
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":
|
case p == expectedNodePath && m == "GET":
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, nodes)}, nil
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, nodes)}, nil
|
||||||
default:
|
default:
|
||||||
@ -124,9 +124,9 @@ func TestTopNodeWithNameMetricsFrom(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api":
|
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":
|
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":
|
case p == expectedNodePath && m == "GET":
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNode)}, nil
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNode)}, nil
|
||||||
default:
|
default:
|
||||||
@ -201,9 +201,9 @@ func TestTopNodeWithLabelSelectorMetricsFrom(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m, _ := req.URL.Path, req.Method, req.URL.RawQuery; {
|
switch p, m, _ := req.URL.Path, req.Method, req.URL.RawQuery; {
|
||||||
case p == "/api":
|
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":
|
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":
|
case p == expectedNodePath && m == "GET":
|
||||||
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
|
||||||
default:
|
default:
|
||||||
@ -278,9 +278,9 @@ func TestTopNodeWithSortByCpuMetricsFrom(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api":
|
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":
|
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":
|
case p == expectedNodePath && m == "GET":
|
||||||
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
|
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
|
||||||
default:
|
default:
|
||||||
@ -364,9 +364,9 @@ func TestTopNodeWithSortByMemoryMetricsFrom(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api":
|
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":
|
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":
|
case p == expectedNodePath && m == "GET":
|
||||||
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
|
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &expectedNodes)}, nil
|
||||||
default:
|
default:
|
||||||
|
@ -18,7 +18,7 @@ package top
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -215,9 +215,9 @@ func TestTopPod(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p := req.URL.Path; {
|
switch p := req.URL.Path; {
|
||||||
case p == "/api":
|
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":
|
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:
|
default:
|
||||||
t.Fatalf("%s: unexpected request: %#v\nGot URL: %#v",
|
t.Fatalf("%s: unexpected request: %#v\nGot URL: %#v",
|
||||||
testCase.name, req, req.URL)
|
testCase.name, req, req.URL)
|
||||||
@ -346,9 +346,9 @@ func TestTopPodNoResourcesFound(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p := req.URL.Path; {
|
switch p := req.URL.Path; {
|
||||||
case p == "/api":
|
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":
|
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":
|
case p == "/api/v1/namespaces/"+testNS+"/pods":
|
||||||
// Top Pod calls this endpoint to check if there are pods whenever it gets no metrics,
|
// 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
|
// so we need to return no pods for this test scenario
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
@ -50,7 +49,7 @@ func marshallBody(metrics interface{}) (io.ReadCloser, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ioutil.NopCloser(bytes.NewReader(result)), nil
|
return io.NopCloser(bytes.NewReader(result)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNodeV1beta1MetricsData() (*metricsv1beta1api.NodeMetricsList, *v1.NodeList) {
|
func testNodeV1beta1MetricsData() (*metricsv1beta1api.NodeMetricsList, *v1.NodeList) {
|
||||||
|
@ -19,7 +19,6 @@ package editor
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"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 {
|
if err := e.Launch(path); err != nil {
|
||||||
return nil, path, err
|
return nil, path, err
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadFile(path)
|
bytes, err := os.ReadFile(path)
|
||||||
return bytes, path, err
|
return bytes, path, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package editor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -51,7 +50,7 @@ func TestEditor(t *testing.T) {
|
|||||||
t.Fatalf("no temp file: %s", path)
|
t.Fatalf("no temp file: %s", path)
|
||||||
}
|
}
|
||||||
defer os.Remove(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))
|
t.Errorf("unexpected file on disk: %v %s", err, string(disk))
|
||||||
}
|
}
|
||||||
if !bytes.Equal(contents, []byte(testStr)) {
|
if !bytes.Equal(contents, []byte(testStr)) {
|
||||||
|
@ -19,7 +19,6 @@ package util
|
|||||||
import (
|
import (
|
||||||
goerrors "errors"
|
goerrors "errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -462,7 +461,7 @@ func testCheckError(t *testing.T, tests []checkErrTestCase) {
|
|||||||
|
|
||||||
func TestDumpReaderToFile(t *testing.T) {
|
func TestDumpReaderToFile(t *testing.T) {
|
||||||
testString := "TEST STRING"
|
testString := "TEST STRING"
|
||||||
tempFile, err := ioutil.TempFile(os.TempDir(), "hlpers_test_dump_")
|
tempFile, err := os.CreateTemp(os.TempDir(), "hlpers_test_dump_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error setting up a temporary file %v", err)
|
t.Errorf("unexpected error setting up a temporary file %v", err)
|
||||||
}
|
}
|
||||||
@ -477,7 +476,7 @@ func TestDumpReaderToFile(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error in DumpReaderToFile: %v", err)
|
t.Errorf("error in DumpReaderToFile: %v", err)
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(tempFile.Name())
|
data, err := os.ReadFile(tempFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error when reading %s: %v", tempFile.Name(), err)
|
t.Errorf("error when reading %s: %v", tempFile.Name(), err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package wait
|
package wait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -963,7 +963,7 @@ func TestWaitForCondition(t *testing.T) {
|
|||||||
Timeout: test.timeout,
|
Timeout: test.timeout,
|
||||||
|
|
||||||
Printer: printers.NewDiscardingPrinter(),
|
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(),
|
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
||||||
}
|
}
|
||||||
err := o.RunWait()
|
err := o.RunWait()
|
||||||
@ -1181,7 +1181,7 @@ func TestWaitForDifferentJSONPathExpression(t *testing.T) {
|
|||||||
ConditionFn: JSONPathWait{
|
ConditionFn: JSONPathWait{
|
||||||
jsonPathCondition: test.jsonPathCond,
|
jsonPathCondition: test.jsonPathCond,
|
||||||
jsonPathParser: j,
|
jsonPathParser: j,
|
||||||
errOut: ioutil.Discard}.IsJSONPathConditionMet,
|
errOut: io.Discard}.IsJSONPathConditionMet,
|
||||||
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1444,7 +1444,7 @@ func TestWaitForJSONPathCondition(t *testing.T) {
|
|||||||
Printer: printers.NewDiscardingPrinter(),
|
Printer: printers.NewDiscardingPrinter(),
|
||||||
ConditionFn: JSONPathWait{
|
ConditionFn: JSONPathWait{
|
||||||
jsonPathCondition: test.jsonPathCond,
|
jsonPathCondition: test.jsonPathCond,
|
||||||
jsonPathParser: j, errOut: ioutil.Discard}.IsJSONPathConditionMet,
|
jsonPathParser: j, errOut: io.Discard}.IsJSONPathConditionMet,
|
||||||
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -361,12 +361,12 @@ func TestFileServing(t *testing.T) {
|
|||||||
fname = "test.txt"
|
fname = "test.txt"
|
||||||
data = "This is test data"
|
data = "This is test data"
|
||||||
)
|
)
|
||||||
dir, err := ioutil.TempDir("", "data")
|
dir, err := os.MkdirTemp("", "data")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating tmp dir: %v", err)
|
t.Fatalf("error creating tmp dir: %v", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
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)
|
t.Fatalf("error writing tmp file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +385,7 @@ func TestFileServing(t *testing.T) {
|
|||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
t.Errorf("res.StatusCode = %d; want %d", 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 {
|
if err != nil {
|
||||||
t.Fatalf("error reading resp body: %v", err)
|
t.Fatalf("error reading resp body: %v", err)
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ func newProxy(target *url.URL) http.Handler {
|
|||||||
|
|
||||||
func TestAPIRequests(t *testing.T) {
|
func TestAPIRequests(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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 {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -487,7 +487,7 @@ func TestPathHandling(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%#v: %v", tt, err)
|
t.Fatalf("%#v: %v", tt, err)
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%#v: %v", tt, err)
|
t.Fatalf("%#v: %v", tt, err)
|
||||||
|
@ -19,7 +19,7 @@ package completion
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -169,7 +169,7 @@ func CompGetContainers(f cmdutil.Factory, cmd *cobra.Command, podName string, to
|
|||||||
// which begin with `toComplete`.
|
// which begin with `toComplete`.
|
||||||
func CompGetFromTemplate(template *string, f cmdutil.Factory, namespace string, cmd *cobra.Command, args []string, toComplete string) []string {
|
func CompGetFromTemplate(template *string, f cmdutil.Factory, namespace string, cmd *cobra.Command, args []string, toComplete string) []string {
|
||||||
buf := new(bytes.Buffer)
|
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)
|
o := get.NewGetOptions("kubectl", streams)
|
||||||
|
|
||||||
// Get the list of names of the specified resource
|
// 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`.
|
// compGetResourceList returns the list of api resources which begin with `toComplete`.
|
||||||
func compGetResourceList(restClientGetter genericclioptions.RESTClientGetter, cmd *cobra.Command, toComplete string) []string {
|
func compGetResourceList(restClientGetter genericclioptions.RESTClientGetter, cmd *cobra.Command, toComplete string) []string {
|
||||||
buf := new(bytes.Buffer)
|
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 := apiresources.NewAPIResourceOptions(streams)
|
||||||
|
|
||||||
o.Complete(restClientGetter, cmd, nil)
|
o.Complete(restClientGetter, cmd, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user