From da4a8d831b933475cfdb20cb7e6d0ed027d516eb Mon Sep 17 00:00:00 2001 From: TommyStarK Date: Sun, 4 Jun 2023 15:45:24 +0200 Subject: [PATCH] kubectl: use bytes.Buffer.String Signed-off-by: TommyStarK --- .../kubectl/pkg/cmd/create/create_clusterrole_test.go | 2 +- staging/src/k8s.io/kubectl/pkg/cmd/label/label_test.go | 2 +- staging/src/k8s.io/kubectl/pkg/cmd/set/set_env_test.go | 6 +++--- staging/src/k8s.io/kubectl/pkg/describe/describe.go | 3 +-- .../src/k8s.io/kubectl/pkg/polymorphichelpers/history.go | 3 +-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_clusterrole_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_clusterrole_test.go index a15f6bd3f3b..140be842047 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_clusterrole_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_clusterrole_test.go @@ -163,7 +163,7 @@ func TestCreateClusterRole(t *testing.T) { cmd.Run(cmd, []string{clusterRoleName}) actual := &rbac.ClusterRole{} if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), buf.Bytes(), actual); err != nil { - t.Log(string(buf.Bytes())) + t.Log(buf.String()) t.Fatal(err) } if !equality.Semantic.DeepEqual(test.expectedClusterRole, actual) { diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/label/label_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/label/label_test.go index dd3173bef47..2f84ee8899d 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/label/label_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/label/label_test.go @@ -365,7 +365,7 @@ func TestLabelErrors(t *testing.T) { return } if buf.Len() > 0 { - t.Errorf("buffer should be empty: %s", string(buf.Bytes())) + t.Errorf("buffer should be empty: %s", buf.String()) } }) } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/set/set_env_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/set/set_env_test.go index b130faac323..d58f6e05ab1 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/set/set_env_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/set/set_env_test.go @@ -72,7 +72,7 @@ func TestSetEnvLocal(t *testing.T) { err = opts.RunEnv() assert.NoError(t, err) if bufErr.Len() > 0 { - t.Errorf("unexpected error: %s", string(bufErr.String())) + t.Errorf("unexpected error: %s", bufErr.String()) } if !strings.Contains(buf.String(), "replicationcontroller/cassandra") { t.Errorf("did not set env: %s", buf.String()) @@ -109,7 +109,7 @@ func TestSetEnvLocalNamespace(t *testing.T) { err = opts.RunEnv() assert.NoError(t, err) if bufErr.Len() > 0 { - t.Errorf("unexpected error: %s", string(bufErr.String())) + t.Errorf("unexpected error: %s", bufErr.String()) } if !strings.Contains(buf.String(), "namespace: existing-ns") { t.Errorf("did not set env: %s", buf.String()) @@ -146,7 +146,7 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) { err = opts.RunEnv() assert.NoError(t, err) if bufErr.Len() > 0 { - t.Errorf("unexpected error: %s", string(bufErr.String())) + t.Errorf("unexpected error: %s", bufErr.String()) } expectedOut := "replicationcontroller/first-rc\nreplicationcontroller/second-rc\n" if buf.String() != expectedOut { diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe.go b/staging/src/k8s.io/kubectl/pkg/describe/describe.go index 4819e95b520..8cc58be09d4 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe.go @@ -5205,8 +5205,7 @@ func tabbedString(f func(io.Writer) error) (string, error) { } out.Flush() - str := string(buf.String()) - return str, nil + return buf.String(), nil } type SortableResourceNames []corev1.ResourceName diff --git a/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/history.go b/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/history.go index 20afbe985a1..aed793018cc 100644 --- a/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/history.go +++ b/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/history.go @@ -464,8 +464,7 @@ func tabbedString(f func(io.Writer) error) (string, error) { } out.Flush() - str := string(buf.String()) - return str, nil + return buf.String(), nil } // getChangeCause returns the change-cause annotation of the input object