-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
58 lines (50 loc) · 2.33 KB
/
config_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 (
"testing"
"time"
)
type configFlagTestTableRow struct {
attrName string
in []string
isGood func(appConfig) bool
}
var configFlagTestTable = []configFlagTestTableRow{
// MaxAgeOfImages
{"MaxAgeOfImages", []string{}, func(c appConfig) bool { return c.MaxAgeOfImages == 168*time.Hour }},
{"MaxAgeOfImages", []string{"--max-image-age=20m"}, func(c appConfig) bool { return c.MaxAgeOfImages == 20*time.Minute }},
{"MaxAgeOfImages", []string{"--max-image-age", "7h"}, func(c appConfig) bool { return c.MaxAgeOfImages == 7*time.Hour }},
{"MaxAgeOfImages", []string{"-m", "5h"}, func(c appConfig) bool { return c.MaxAgeOfImages == 5*time.Hour }},
// SweeperTime
{"SweeperTime", []string{}, func(c appConfig) bool { return c.SweeperTime == 15*time.Minute }},
{"SweeperTime", []string{"--sweeper-time=11m"}, func(c appConfig) bool { return c.SweeperTime == 11*time.Minute }},
{"SweeperTime", []string{"--sweeper-time", "2h"}, func(c appConfig) bool { return c.SweeperTime == 2*time.Hour }},
{"SweeperTime", []string{"-s", "30s"}, func(c appConfig) bool { return c.SweeperTime == 30*time.Second }},
// DangleSafeDuration
{"DangleSafeDuration", []string{}, func(c appConfig) bool { return c.DangleSafeDuration == 30*time.Minute }},
{"DangleSafeDuration", []string{"--dangle-safe-duration=11m"}, func(c appConfig) bool { return c.DangleSafeDuration == 11*time.Minute }},
{"DangleSafeDuration", []string{"--dangle-safe-duration", "2h"}, func(c appConfig) bool { return c.DangleSafeDuration == 2*time.Hour }},
{"DangleSafeDuration", []string{"-d", "30s"}, func(c appConfig) bool { return c.DangleSafeDuration == 30*time.Second }},
// Quiet
{"Quiet", []string{}, func(c appConfig) bool { return !c.Quiet }},
{"Quiet", []string{"-q"}, func(c appConfig) bool { return c.Quiet }},
{"Quiet", []string{"--quiet"}, func(c appConfig) bool { return c.Quiet }},
}
func TestConfigFlagTestTable(t *testing.T) {
for _, tt := range configFlagTestTable {
config, err := newAppConfig(tt.in)
if err != nil {
t.Errorf("args %q; got error %q", tt.in, err)
}
if !tt.isGood(config) {
t.Errorf("args %v config => %+v", tt.in, config)
}
}
}
// See issue #4
func TestBogusFlag(t *testing.T) {
args := []string{"--bogus-flag"}
_, err := newAppConfig(args)
if err == nil {
t.Errorf("args %q; expected error, but got nothing", args)
}
}