-
Notifications
You must be signed in to change notification settings - Fork 6
/
features_test.go
60 lines (55 loc) · 1.85 KB
/
features_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
package gox_test
import (
"testing"
"github.com/goexl/gox"
)
const (
Feature1 = iota + 1
Feature2
Feature3
Feature4
)
func TestFeaturesEnableAny(t *testing.T) {
tests := []struct {
enabled []gox.Feature
checks []gox.Feature
expected bool
}{
{[]gox.Feature{Feature1}, []gox.Feature{Feature1}, true},
{[]gox.Feature{Feature1}, []gox.Feature{Feature4}, false},
{[]gox.Feature{Feature1, Feature3}, []gox.Feature{Feature3}, true},
{[]gox.Feature{Feature1, Feature4}, []gox.Feature{Feature1}, true},
{[]gox.Feature{Feature1, Feature2, Feature4}, []gox.Feature{Feature1, Feature2}, true},
{[]gox.Feature{Feature1, Feature2, Feature4}, []gox.Feature{Feature3}, false},
}
for index, test := range tests {
features := gox.NewFeatures()
features.Enable(test.enabled[0], test.enabled[1:]...)
got := features.Any(test.checks[0], test.checks[1:]...)
if test.expected != got {
t.Errorf("第%d个测试未通过,实际:%v,期望:%v", index+1, got, test.expected)
}
}
}
func TestFeaturesEnableAll(t *testing.T) {
tests := []struct {
enabled []gox.Feature
checks []gox.Feature
expected bool
}{
{[]gox.Feature{Feature1}, []gox.Feature{Feature1}, true},
{[]gox.Feature{Feature1}, []gox.Feature{Feature4}, false},
{[]gox.Feature{Feature1, Feature3}, []gox.Feature{Feature3}, true},
{[]gox.Feature{Feature1, Feature4}, []gox.Feature{Feature1}, true},
{[]gox.Feature{Feature1, Feature2, Feature4}, []gox.Feature{Feature1, Feature2}, true},
{[]gox.Feature{Feature1, Feature2, Feature4}, []gox.Feature{Feature3}, false},
}
for index, test := range tests {
features := gox.NewFeatures()
features.Enable(test.enabled[0], test.enabled[1:]...)
got := features.All(test.checks[0], test.checks[1:]...)
if test.expected != got {
t.Errorf("第%d个测试未通过,实际:%v,期望:%v", index+1, got, test.expected)
}
}
}