-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathparse_args_test.go
More file actions
52 lines (49 loc) · 1.18 KB
/
parse_args_test.go
File metadata and controls
52 lines (49 loc) · 1.18 KB
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
package main
import (
"errors"
"testing"
)
func TestParseArgs(t *testing.T) {
type testConfig struct {
args []string
err error
config
}
tests := []testConfig{
{
args: []string{"-h"},
err: nil,
config: config{printUsage: true, numTimes: 0},
},
{
args: []string{"10"},
err: nil,
config: config{printUsage: false, numTimes: 10},
},
{
args: []string{"abc"},
err: errors.New("strconv.Atoi: parsing \"abc\": invalid syntax"),
config: config{printUsage: false, numTimes: 0},
},
{
args: []string{"1", "foo"},
err: errors.New("Invalid number of arguments"),
config: config{printUsage: false, numTimes: 0},
},
}
for _, tc := range tests {
c, err := parseArgs(tc.args)
if tc.err != nil && err.Error() != tc.err.Error() {
t.Fatalf("Expected error to be: %v, got: %v\n", tc.err, err)
}
if tc.err == nil && err != nil {
t.Fatalf("Expected nil error, got: %v\n", err)
}
if c.printUsage != tc.printUsage {
t.Errorf("Expected printUsage to be: %v, got: %v\n", tc.printUsage, c.printUsage)
}
if c.numTimes != tc.numTimes {
t.Errorf("Expected numTimes to be: %v, got: %v\n", tc.numTimes, c.numTimes)
}
}
}