-
Notifications
You must be signed in to change notification settings - Fork 255
/
Copy pathrm_test.go
73 lines (68 loc) · 1.68 KB
/
rm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package command
import (
"flag"
"testing"
"github.com/urfave/cli/v2"
)
func TestValidateRMCommand(t *testing.T) {
t.Parallel()
tests := []struct {
name string
sources []string
expectedErrStr string
}{
{
name: "error_if_local_and_remote_mixed",
sources: []string{
"s3://bucket/key",
"filename.txt",
},
expectedErrStr: "arguments cannot have both local and remote sources",
},
{
name: "error_if_sources_have_bucket",
sources: []string{
"s3://bucket/key",
"s3://bucket",
},
expectedErrStr: "s3 bucket/prefix cannot be used for delete operations (forgot wildcard character?)",
},
{
name: "error_if_sources_have_s3_prefix",
sources: []string{
"s3://bucket/prefix/",
},
expectedErrStr: "s3 bucket/prefix cannot be used for delete operations (forgot wildcard character?)",
},
{
name: "success",
sources: []string{
"s3://bucket/prefix/filename.txt",
"s3://bucket/wildcard/*.txt",
},
},
{
name: "error_if_different_buckets",
sources: []string{
"s3://bucket/object",
"s3://someotherbucket/object",
},
expectedErrStr: "removal of objects with different buckets in a single command is not allowed",
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
flagset := flag.NewFlagSet("rm", flag.ExitOnError)
if err := flagset.Parse(tc.sources); err != nil {
t.Error(err)
}
ctx := cli.NewContext(app, flagset, nil)
err := validateRMCommand(ctx)
if (err != nil && err.Error() != tc.expectedErrStr) ||
(err == nil && tc.expectedErrStr != "") {
t.Errorf("expected_got = %v, error_expected = %v", err, tc.expectedErrStr)
}
})
}
}