-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflags_test.go
78 lines (67 loc) · 2.42 KB
/
flags_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
74
75
76
77
78
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func getDefaultBool(priorityBool bool, fallbackBool bool) bool {
if !priorityBool {
return fallbackBool
}
return priorityBool
}
func getDefaultInt(priorityInt int, fallbackInt int) int {
if priorityInt == 0 {
return fallbackInt
}
return priorityInt
}
func getDefaultUint64(priorityInt uint64, fallbackInt uint64) uint64 {
if priorityInt == 0 {
return fallbackInt
}
return priorityInt
}
func TestParseFlags(t *testing.T) {
var tests = []struct {
input []string
flags Flags
config Config
}{
{[]string{},
Flags{},
Config{}},
{[]string{},
Flags{},
Config{Errors: 555, Nulls: true, Quiet: true, Retries: 11, Workers: 12}},
{[]string{"-c", "config.json", "-e", "1000", "-n", "-o", "testOut.json", "-p", "100", "-q", "-r", "7", "-v", "-w", "9"},
Flags{config: "config.json", Args: Args{errors: 1000, nulls: true, out: "testOut.json", page: 100, quiet: true, retries: 7, workers: 9}, version: true},
Config{}},
}
for _, tt := range tests {
t.Run(strings.Join(tt.input, " "), func(t *testing.T) {
flags, _ := parseFlags("bigboy", tt.input, &tt.config)
var expectedConfig string = defaultConfig
if tt.flags.config != "" {
expectedConfig = tt.flags.config
}
expectedErrors := getDefaultUint64(tt.flags.errors, tt.config.Errors)
expectedNulls := getDefaultBool(tt.flags.nulls, tt.config.Nulls)
expectedPage := getDefaultInt(tt.flags.page, tt.config.Page)
expectedQuiet := getDefaultBool(tt.flags.quiet, tt.config.Quiet)
expectedRetries := getDefaultUint64(tt.flags.retries, tt.config.Retries)
expectedWorkers := getDefaultInt(tt.flags.workers, tt.config.Workers)
assert.Equal(t, expectedConfig, flags.config, "Args config set")
assert.Equal(t, expectedErrors, flags.errors, "Args errors set")
assert.Equal(t, expectedNulls, flags.nulls, "Args nulls set")
assert.Equal(t, tt.flags.out, flags.out, "Args out set")
assert.Equal(t, expectedPage, flags.page, "Args page set")
assert.Equal(t, tt.flags.params, flags.params, "Args params set")
assert.Equal(t, expectedQuiet, flags.quiet, "Args quiet set")
assert.Equal(t, expectedRetries, flags.retries, "Args retries set")
assert.Equal(t, tt.flags.target, flags.target, "Args target set")
assert.Equal(t, tt.flags.version, flags.version, "Args version set")
assert.Equal(t, expectedWorkers, flags.workers, "Args workers set")
})
}
}