-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp_configurator_test.go
54 lines (46 loc) · 1.16 KB
/
help_configurator_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
package cfg
import (
"bytes"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type helpStructConfig struct {
Yolo string `help:"this is the help message" flag:"yolo,y"`
}
func TestPrintDefaults(t *testing.T) {
for _, tt := range []struct {
in interface{}
out string
}{
{
in: &mapStringIntStruct{},
out: "Arguments:\n\t- Map: map[string]integer (env: MAP, flag: --map)\n",
},
{
in: &mapStringIntStruct{Map: map[string]int{"fiz": 42}},
out: "Arguments:\n\t- Map: map[string]integer (default: map[fiz:42]) (env: MAP, flag: --map)\n",
},
{
in: &nestedPtrStruct{},
out: "Arguments:\n\t- Nested.Inner: integer (env: NESTED_INNER, flag: --nested.inner)\n",
},
{
in: &durationStruct{D: 5 * time.Hour},
out: "Arguments:\n\t- D: duration (default: 5h0m0s) (env: D, flag: -d)\n",
},
{
in: &helpStructConfig{},
out: "Arguments:\n\t- Yolo: string this is the help message (env: YOLO, flag: --yolo, -y)\n",
},
} {
var (
b bytes.Buffer
cfg = NewDefaultConfigurator().(*helpConfigurator)
)
cfg.stderr = &b
err := cfg.PrintDefaults(tt.in)
assert.NoError(t, err)
assert.Equal(t, tt.out, b.String())
}
}