-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
58 lines (53 loc) · 939 Bytes
/
main_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
package main
import (
"bytes"
"strings"
"testing"
)
func TestRun(t *testing.T) {
tc := map[string]struct {
args []string
err string
}{
"UnkownFlagFailsParsing": {
args: []string{
"sure",
"-unkownflag",
},
err: "-unkownflag",
},
"SrcIsMandatory": {
args: []string{
"sure",
"-dest",
t.TempDir(),
},
err: "src must be provided",
},
"DestIsMandatory": {
args: []string{
"sure",
"-src",
t.TempDir(),
},
err: "dest must be provided",
},
}
for k, tc := range tc {
t.Run(k, func(t *testing.T) {
var out bytes.Buffer
err := run(tc.args, &out)
if tc.err != "" {
if err == nil {
t.Fatal("expected an error but got none")
}
if !strings.Contains(err.Error(), tc.err) {
t.Fatalf("got error %q but want %q", err, tc.err)
}
}
if tc.err == "" && err != nil {
t.Fatalf("expected no error but got: %s", err)
}
})
}
}