fix defer in for loop, maybe resource leak
Kubernetes-commit: 684c5bf2a77f96b7db608e3c726a1d7da1a68421
This commit is contained in:
parent
c26d922e2e
commit
46b7c48533
|
@ -27,16 +27,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetupOutputWriterNoOp(t *testing.T) {
|
func TestSetupOutputWriterNoOp(t *testing.T) {
|
||||||
tests := []string{"", "-"}
|
tests := []struct {
|
||||||
for _, test := range tests {
|
name string
|
||||||
_, _, buf, _ := genericclioptions.NewTestIOStreams()
|
outputWriter string
|
||||||
f := cmdtesting.NewTestFactory()
|
}{
|
||||||
defer f.Cleanup()
|
{
|
||||||
|
name: "empty",
|
||||||
|
outputWriter: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "stdout",
|
||||||
|
outputWriter: "-",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
tt := tt
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
_, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
f := cmdtesting.NewTestFactory()
|
||||||
|
defer f.Cleanup()
|
||||||
|
|
||||||
writer := setupOutputWriter(test, buf, "/some/file/that/should/be/ignored", "")
|
writer := setupOutputWriter(tt.outputWriter, buf, "/some/file/that/should/be/ignored", "")
|
||||||
if writer != buf {
|
if writer != buf {
|
||||||
t.Errorf("expected: %v, saw: %v", buf, writer)
|
t.Errorf("expected: %v, saw: %v", buf, writer)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue