Additional test coverage for kubectl/cmd/cp

This commit adds some additional test coverage
for the kubectl cp command.
pull/8/head
Michael Gugino 2018-05-15 18:05:36 -04:00
parent b71fe87a5c
commit 442b3fcf00
1 changed files with 36 additions and 0 deletions

View File

@ -74,6 +74,10 @@ func TestExtractFileSpec(t *testing.T) {
spec: "some:bad:spec",
expectErr: true,
},
{
spec: "namespace/pod/invalid:/some/file",
expectErr: true,
},
}
for _, test := range tests {
spec, err := extractFileSpec(test.spec)
@ -579,3 +583,35 @@ func TestCopyToPod(t *testing.T) {
})
}
}
func TestValidate(t *testing.T) {
tests := []struct {
name string
args []string
expectedErr bool
}{
{
name: "Validate Succeed",
args: []string{"1", "2"},
expectedErr: false,
},
{
name: "Validate Fail",
args: []string{"1", "2", "3"},
expectedErr: true,
},
}
tf := cmdtesting.NewTestFactory()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams()
opts := NewCopyOptions(ioStreams)
cmd := NewCmdCp(tf, ioStreams)
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := opts.Validate(cmd, test.args)
if (err != nil) != test.expectedErr {
t.Errorf("expected error: %v, saw: %v, error: %v", test.expectedErr, err != nil, err)
}
})
}
}