-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
option_test.go
87 lines (84 loc) · 2.45 KB
/
option_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
79
80
81
82
83
84
85
86
87
package config
import (
"flag"
"github.com/cshum/imagor"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"testing"
)
func TestApplyOptions(t *testing.T) {
fs := flag.NewFlagSet("imagor", flag.ExitOnError)
nopLogger := zap.NewNop()
var seq []int
options, logger, isDebug := applyOptions(fs, func() (logger *zap.Logger, isDebug bool) {
seq = append(seq, 4)
return nopLogger, true
}, func(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
seq = append(seq, 3)
logger, isDebug := cb()
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
seq = append(seq, 5)
return func(app *imagor.Imagor) {
seq = append(seq, 8)
}
}, func(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
seq = append(seq, 2)
logger, isDebug := cb()
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
seq = append(seq, 6)
return func(app *imagor.Imagor) {
seq = append(seq, 9)
}
}, func(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
seq = append(seq, 1)
logger, isDebug := cb()
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
seq = append(seq, 7)
return func(app *imagor.Imagor) {
seq = append(seq, 10)
}
})
imagor.New(options...)
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
assert.Equal(t, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, seq)
}
func TestApplyFuncsNil(t *testing.T) {
fs := flag.NewFlagSet("imagor", flag.ExitOnError)
nopLogger := zap.NewNop()
var seq []int
options, logger, isDebug := applyOptions(fs, func() (logger *zap.Logger, isDebug bool) {
seq = append(seq, 4)
return nopLogger, true
}, func(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
seq = append(seq, 3)
logger, isDebug := cb()
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
seq = append(seq, 5)
return func(app *imagor.Imagor) {
seq = append(seq, 7)
}
}, nil, func(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
seq = append(seq, 2)
return func(app *imagor.Imagor) {
seq = append(seq, 8)
}
}, nil, func(fs *flag.FlagSet, cb func() (*zap.Logger, bool)) imagor.Option {
seq = append(seq, 1)
logger, isDebug := cb()
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
seq = append(seq, 6)
return func(app *imagor.Imagor) {
seq = append(seq, 9)
}
})
imagor.New(options...)
assert.Equal(t, nopLogger, logger)
assert.True(t, isDebug)
assert.Equal(t, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}, seq)
}