Merge pull request #63890 from mgugino-upstream-stage/kubectl-cp-add-tests

Automatic merge from submit-queue (batch tested with PRs 63319, 64248, 64250, 63890, 64233). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Additional test coverage for kubectl/cmd/cp

This commit adds some additional test coverage
for the kubectl cp command.

**Release note**:

```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-05-24 19:46:18 -07:00 committed by GitHub
commit 9de1db7c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
}
})
}
}