mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-24 03:18:57 +00:00
kube-proxy: minor cleanup
Get rid of overlapping helper functions.
This commit is contained in:
@@ -481,18 +481,6 @@ func WriteLine(buf *bytes.Buffer, words ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
// WriteRuleLine prepends the strings "-A" and chainName to the buffer and calls
|
||||
// WriteLine to join all the words into the buffer and terminate with newline.
|
||||
func WriteRuleLine(buf *bytes.Buffer, chainName string, words ...string) {
|
||||
if len(words) == 0 {
|
||||
return
|
||||
}
|
||||
buf.WriteString("-A ")
|
||||
buf.WriteString(chainName)
|
||||
buf.WriteByte(' ')
|
||||
WriteLine(buf, words...)
|
||||
}
|
||||
|
||||
// WriteBytesLine write bytes to buffer, terminate with newline
|
||||
func WriteBytesLine(buf *bytes.Buffer, bytes []byte) {
|
||||
buf.Write(bytes)
|
||||
|
@@ -1183,44 +1183,6 @@ func TestWriteLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteRuleLine(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
chainName string
|
||||
words []string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "write no line due to no words",
|
||||
chainName: "KUBE-SVC-FOO",
|
||||
words: []string{},
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "write one line",
|
||||
chainName: "KUBE-XLB-FOO",
|
||||
words: []string{"test1"},
|
||||
expected: "-A KUBE-XLB-FOO test1\n",
|
||||
},
|
||||
{
|
||||
name: "write multi word line",
|
||||
chainName: "lolChain",
|
||||
words: []string{"test1", "test2", "test3"},
|
||||
expected: "-A lolChain test1 test2 test3\n",
|
||||
},
|
||||
}
|
||||
testBuffer := bytes.NewBuffer(nil)
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
testBuffer.Reset()
|
||||
WriteRuleLine(testBuffer, testCase.chainName, testCase.words...)
|
||||
if !strings.EqualFold(testBuffer.String(), testCase.expected) {
|
||||
t.Fatalf("write word is %v\n expected: %s, got: %s", testCase.words, testCase.expected, testBuffer.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteBytesLine(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
Reference in New Issue
Block a user