kubectl: use bytes.Buffer.String

Signed-off-by: TommyStarK <thomasmilox@gmail.com>
This commit is contained in:
TommyStarK 2023-06-04 15:45:24 +02:00
parent eca1f9d2d5
commit da4a8d831b
5 changed files with 7 additions and 9 deletions

View File

@ -163,7 +163,7 @@ func TestCreateClusterRole(t *testing.T) {
cmd.Run(cmd, []string{clusterRoleName}) cmd.Run(cmd, []string{clusterRoleName})
actual := &rbac.ClusterRole{} actual := &rbac.ClusterRole{}
if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), buf.Bytes(), actual); err != nil { if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), buf.Bytes(), actual); err != nil {
t.Log(string(buf.Bytes())) t.Log(buf.String())
t.Fatal(err) t.Fatal(err)
} }
if !equality.Semantic.DeepEqual(test.expectedClusterRole, actual) { if !equality.Semantic.DeepEqual(test.expectedClusterRole, actual) {

View File

@ -365,7 +365,7 @@ func TestLabelErrors(t *testing.T) {
return return
} }
if buf.Len() > 0 { if buf.Len() > 0 {
t.Errorf("buffer should be empty: %s", string(buf.Bytes())) t.Errorf("buffer should be empty: %s", buf.String())
} }
}) })
} }

View File

@ -72,7 +72,7 @@ func TestSetEnvLocal(t *testing.T) {
err = opts.RunEnv() err = opts.RunEnv()
assert.NoError(t, err) assert.NoError(t, err)
if bufErr.Len() > 0 { 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") { if !strings.Contains(buf.String(), "replicationcontroller/cassandra") {
t.Errorf("did not set env: %s", buf.String()) t.Errorf("did not set env: %s", buf.String())
@ -109,7 +109,7 @@ func TestSetEnvLocalNamespace(t *testing.T) {
err = opts.RunEnv() err = opts.RunEnv()
assert.NoError(t, err) assert.NoError(t, err)
if bufErr.Len() > 0 { 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") { if !strings.Contains(buf.String(), "namespace: existing-ns") {
t.Errorf("did not set env: %s", buf.String()) t.Errorf("did not set env: %s", buf.String())
@ -146,7 +146,7 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
err = opts.RunEnv() err = opts.RunEnv()
assert.NoError(t, err) assert.NoError(t, err)
if bufErr.Len() > 0 { 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" expectedOut := "replicationcontroller/first-rc\nreplicationcontroller/second-rc\n"
if buf.String() != expectedOut { if buf.String() != expectedOut {

View File

@ -5205,8 +5205,7 @@ func tabbedString(f func(io.Writer) error) (string, error) {
} }
out.Flush() out.Flush()
str := string(buf.String()) return buf.String(), nil
return str, nil
} }
type SortableResourceNames []corev1.ResourceName type SortableResourceNames []corev1.ResourceName

View File

@ -464,8 +464,7 @@ func tabbedString(f func(io.Writer) error) (string, error) {
} }
out.Flush() out.Flush()
str := string(buf.String()) return buf.String(), nil
return str, nil
} }
// getChangeCause returns the change-cause annotation of the input object // getChangeCause returns the change-cause annotation of the input object