-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclop_once_test.go
89 lines (84 loc) · 2.02 KB
/
clop_once_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
88
89
package clop
import (
"github.com/stretchr/testify/assert"
"testing"
)
//测试once功能打开
func Test_Once_Open(t *testing.T) {
type once struct {
Debug bool `clop:"-d; --debug; once" usage:"debug mode"`
}
type onceString struct {
Addr string `clop:"-a; --addr; once" usage:"server address"`
}
type onceInt struct {
MaxThread int `clop:"-t; --max-thread; once" usage:"max thread"`
}
for range []struct{}{
func() struct{} {
h := once{}
p := New([]string{"-d", "-d"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := once{}
p := New([]string{"--debug", "-d"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := once{}
p := New([]string{"-d", "--debug"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := once{}
p := New([]string{"--debug", "--debug"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := onceString{}
p := New([]string{"-a", ":8080", "-a", ":1234"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := onceString{}
p := New([]string{"--addr", ":8080", "-a", ":1234"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := onceString{}
p := New([]string{"--a", ":8080", "--addr", ":1234"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := onceString{}
p := New([]string{"--addr", ":8080", "--addr", ":1234"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
return struct{}{}
}(),
func() struct{} {
h := onceInt{}
p := New([]string{"--max-thread", "20", "--max-thread", "50"}).SetExit(false)
err := p.Bind(&h)
assert.Error(t, err)
assert.Equal(t, h, onceInt{MaxThread: 20})
return struct{}{}
}(),
} {
}
}