diff --git a/pkg/proxy/ipvs/proxier_test.go b/pkg/proxy/ipvs/proxier_test.go index 6a17f081cbe..b672ed649e8 100644 --- a/pkg/proxy/ipvs/proxier_test.go +++ b/pkg/proxy/ipvs/proxier_test.go @@ -4660,8 +4660,8 @@ func TestCreateAndLinkKubeChain(t *testing.T) { :KUBE-SOURCE-RANGES-FIREWALL - [0:0] :KUBE-IPVS-FILTER - [0:0] ` - assert.Equal(t, expectedNATChains, string(fp.natChains.Bytes())) - assert.Equal(t, expectedFilterChains, string(fp.filterChains.Bytes())) + assert.Equal(t, expectedNATChains, fp.natChains.String()) + assert.Equal(t, expectedFilterChains, fp.filterChains.String()) } // This test ensures that the iptables proxier supports translating Endpoints to diff --git a/pkg/proxy/util/utils.go b/pkg/proxy/util/utils.go index 319daf27b4a..44140e9fd97 100644 --- a/pkg/proxy/util/utils.go +++ b/pkg/proxy/util/utils.go @@ -483,6 +483,11 @@ func (buf *LineBuffer) Bytes() []byte { return buf.b.Bytes() } +// String returns the contents of buf as a string +func (buf *LineBuffer) String() string { + return buf.b.String() +} + // Lines returns the number of lines in buf. Note that more precisely, this returns the // number of times Write() or WriteBytes() was called; it assumes that you never wrote // any newlines to the buffer yourself. diff --git a/pkg/proxy/util/utils_test.go b/pkg/proxy/util/utils_test.go index 39e0ac573fb..81468bb2522 100644 --- a/pkg/proxy/util/utils_test.go +++ b/pkg/proxy/util/utils_test.go @@ -962,7 +962,7 @@ func TestLineBufferWrite(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { testBuffer.Reset() testBuffer.Write(testCase.input...) - if want, got := testCase.expected, string(testBuffer.Bytes()); !strings.EqualFold(want, got) { + if want, got := testCase.expected, testBuffer.String(); !strings.EqualFold(want, got) { t.Fatalf("write word is %v\n expected: %q, got: %q", testCase.input, want, got) } if testBuffer.Lines() != 1 { @@ -1005,7 +1005,7 @@ func TestLineBufferWriteBytes(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { testBuffer.Reset() testBuffer.WriteBytes(testCase.bytes) - if want, got := testCase.expected, string(testBuffer.Bytes()); !strings.EqualFold(want, got) { + if want, got := testCase.expected, testBuffer.String(); !strings.EqualFold(want, got) { t.Fatalf("write bytes is %v\n expected: %s, got: %s", testCase.bytes, want, got) } }) diff --git a/pkg/util/iptables/testing/fake_test.go b/pkg/util/iptables/testing/fake_test.go index 413610a6d81..a20917c036d 100644 --- a/pkg/util/iptables/testing/fake_test.go +++ b/pkg/util/iptables/testing/fake_test.go @@ -49,7 +49,7 @@ func TestFakeIPTables(t *testing.T) { *mangle COMMIT `, "\n")) - if string(buf.Bytes()) != expected { + if buf.String() != expected { t.Fatalf("bad initial dump. expected:\n%s\n\ngot:\n%s\n", expected, buf.Bytes()) } @@ -143,7 +143,7 @@ func TestFakeIPTables(t *testing.T) { *mangle COMMIT `, "\n")) - if string(buf.Bytes()) != expected { + if buf.String() != expected { t.Fatalf("bad sanity-check dump. expected:\n%s\n\ngot:\n%s\n", expected, buf.Bytes()) } @@ -214,7 +214,7 @@ func TestFakeIPTables(t *testing.T) { *mangle COMMIT `, "\n")) - if string(buf.Bytes()) != expected { + if buf.String() != expected { t.Fatalf("bad post-restore dump. expected:\n%s\n\ngot:\n%s\n", expected, buf.Bytes()) } @@ -282,7 +282,7 @@ func TestFakeIPTables(t *testing.T) { *mangle COMMIT `, "\n")) - if string(buf.Bytes()) != expected { + if buf.String() != expected { t.Fatalf("bad post-second-restore dump. expected:\n%s\n\ngot:\n%s\n", expected, buf.Bytes()) } @@ -339,7 +339,7 @@ func TestFakeIPTables(t *testing.T) { *mangle COMMIT `, "\n")) - if string(buf.Bytes()) != expected { + if buf.String() != expected { t.Fatalf("bad post-restore-all dump. expected:\n%s\n\ngot:\n%s\n", expected, buf.Bytes()) } }