-
Notifications
You must be signed in to change notification settings - Fork 33
/
basket_test.go
144 lines (126 loc) · 4.63 KB
/
basket_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"os"
"strings"
"testing"
"github.com/nokia/ntt/ttcn3/doc"
)
func TestBasketMatch(t *testing.T) {
tests := []struct {
basket string
name string
tags []string
want bool
}{
{basket: "", name: "", want: true},
{basket: "", name: "", tags: []string{"@wip"}, want: true},
{basket: "", name: "foo", want: true},
{basket: "", name: "foo", tags: []string{"@wip"}, want: true},
{basket: "-r fo.", name: "foobar", want: true},
{basket: "-r foo|bar", name: "bar", want: true},
{basket: "-r foo", name: "bar", want: false},
{basket: "-x fo.", name: "foo", want: false},
{basket: "-r foo -r bar", name: "foo", want: false},
{basket: "-r foo -r bar", name: "foobar", want: true},
{basket: "-r foo -x bar", name: "foobar", want: false},
{basket: "-x foo -r bar", name: "foobar", want: false},
{basket: "-x foo|bar", name: "bar", want: false},
{basket: "-x foo", name: "bar", want: true},
{basket: "-X @foo|@bar", want: true},
{basket: "-R foo", tags: []string{"@foo bar"}, want: true},
{basket: "-R foo:bar", tags: []string{"@foo bar"}, want: true},
{basket: "-R :bar", tags: []string{"@foo bar"}, want: true},
{basket: "-R :bar", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R bar", tags: []string{"@foo bar"}, want: false},
{basket: "-R bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo|bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -R bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -R wip", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R foo -R bar|wip", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -X bar", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-X bar -R foo", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R foo -X wip", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -X foo", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R foo|wip -R bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-r foo -X @wip", name: "foo", tags: []string{"@foo"}, want: true},
{basket: "-r foo -X @foo", name: "foo", tags: []string{"@foo"}, want: false},
{basket: "-x foo -X @foo", name: "foo", tags: []string{"@foo"}, want: false},
{basket: "-x foo -X @wip", name: "foo", tags: []string{"@foo"}, want: false},
{basket: "-x foo -R @foo", name: "foo", tags: []string{"@foo"}, want: false},
}
for _, tt := range tests {
b, err := NewBasket("testBasket", strings.Fields(tt.basket)...)
if err != nil {
t.Fatal(err)
}
actual := b.Match(tt.name, doc.FindAllTags(strings.Join(tt.tags, "\n")))
if actual != tt.want {
t.Errorf("Basket(%q).Match(%q, %q) = %v, want %v", tt.basket, tt.name, tt.tags, actual, tt.want)
}
}
}
func TestSubBaskets(t *testing.T) {
tests := []struct {
basket string
name string
tags []string
want bool
}{
{basket: "-r foo:-r bar", name: "foo", want: true},
{basket: "-r foo:-r bar", name: "bar", want: true},
{basket: "-r foo:-x foo", name: "foo", want: true},
{basket: "-r foo -x bar:-x foo", name: "foobar", want: false},
{basket: "-r foo:-x foo:-x foo", name: "foobar", want: true},
{basket: "-r foo:-x foo:-x bar", name: "foobar", want: true},
}
for _, tt := range tests {
b, err := NewBasket("testBasket")
if err != nil {
t.Fatal(err)
}
for _, s := range strings.Split(tt.basket, ":") {
sb, err := NewBasket("subBasket", strings.Fields(s)...)
if err != nil {
t.Fatal(err)
}
b.Baskets = append(b.Baskets, sb)
}
actual := b.Match(tt.name, doc.FindAllTags(strings.Join(tt.tags, "\n")))
if actual != tt.want {
t.Errorf("Basket(%q).Match(%q, %q) = %v, want %v", tt.basket, tt.name, tt.tags, actual, tt.want)
}
}
}
func TestLoadFromEnv(t *testing.T) {
os.Setenv("TEST_BASKET", "stable:wip")
os.Setenv("TEST_BASKET_stable", "-X @wip|@flaky")
defer func() {
os.Unsetenv("TEST_BASKET")
os.Unsetenv("TEST_BASKET_stable")
}()
b, err := NewBasket("testBasket", "-r", "foo")
if err != nil {
t.Fatal(err)
}
b.LoadFromEnvOrConfig(nil, "TEST_BASKET")
test := []struct {
name string
tags []string
want bool
}{
{name: "foo", want: true},
{name: "foo", tags: []string{"@wip"}, want: true},
{name: "foo", tags: []string{"@flaky"}, want: false},
{name: "bar", want: false},
{name: "bar", tags: []string{"@wip"}, want: false},
{name: "bar", tags: []string{"@false"}, want: false},
}
for _, tt := range test {
t.Run(tt.name, func(t *testing.T) {
actual := b.Match(tt.name, doc.FindAllTags(strings.Join(tt.tags, "\n")))
if actual != tt.want {
t.Errorf("Basket.Match(%q, %q) = %v, want %v", tt.name, tt.tags, actual, tt.want)
}
})
}
}