-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathrunnergroups_test.go
94 lines (64 loc) · 2.38 KB
/
runnergroups_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
package simulator
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestVisibleRunnerGroupsInsert(t *testing.T) {
g := NewVisibleRunnerGroups()
orgDefault := NewRunnerGroupFromProperties("", "myorg1", "")
orgCustom := NewRunnerGroupFromProperties("", "myorg1", "myorg1group1")
enterpriseDefault := NewRunnerGroupFromProperties("myenterprise1", "", "")
g.insert(orgCustom, 0)
g.insert(orgDefault, 0)
g.insert(enterpriseDefault, 1)
var got []RunnerGroup
err := g.Traverse(func(rg RunnerGroup) (bool, error) {
got = append(got, rg)
return false, nil
})
require.NoError(t, err)
require.Equal(t, []RunnerGroup{orgDefault, enterpriseDefault, orgCustom}, got, "Unexpected result")
}
func TestVisibleRunnerGroups(t *testing.T) {
v := NewVisibleRunnerGroups()
requireGroups := func(t *testing.T, included, notIncluded []RunnerGroup) {
t.Helper()
for _, rg := range included {
if !v.Includes(rg) {
t.Errorf("%v must be included", rg)
}
}
for _, rg := range notIncluded {
if v.Includes(rg) {
t.Errorf("%v must not be included", rg)
}
}
var got []RunnerGroup
err := v.Traverse(func(rg RunnerGroup) (bool, error) {
got = append(got, rg)
return false, nil
})
require.NoError(t, err)
require.Equal(t, included, got)
}
orgDefault := NewRunnerGroupFromProperties("", "myorg1", "")
orgCustom := NewRunnerGroupFromProperties("", "myorg1", "myorg1group1")
enterpriseDefault := NewRunnerGroupFromProperties("myenterprise1", "", "")
enterpriseCustom := NewRunnerGroupFromProperties("myenterprise1", "", "myenterprise1group1")
requireGroups(t, nil, []RunnerGroup{orgDefault, enterpriseDefault, orgCustom, enterpriseCustom})
v.Add(orgCustom)
requireGroups(t, []RunnerGroup{orgCustom}, []RunnerGroup{orgDefault, enterpriseDefault, enterpriseCustom})
v.Add(orgDefault)
requireGroups(t, []RunnerGroup{orgDefault, orgCustom}, []RunnerGroup{enterpriseDefault, enterpriseCustom})
v.Add(enterpriseCustom)
requireGroups(t, []RunnerGroup{orgDefault, orgCustom, enterpriseCustom}, []RunnerGroup{enterpriseDefault})
v.Add(enterpriseDefault)
requireGroups(t, []RunnerGroup{orgDefault, enterpriseDefault, orgCustom, enterpriseCustom}, nil)
var first []RunnerGroup
err := v.Traverse(func(rg RunnerGroup) (bool, error) {
first = append(first, rg)
return true, nil
})
require.NoError(t, err)
require.Equal(t, []RunnerGroup{orgDefault}, first)
}