-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathutils_test.go
More file actions
136 lines (130 loc) · 3.21 KB
/
utils_test.go
File metadata and controls
136 lines (130 loc) · 3.21 KB
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
package actionsgithubcom
import (
"reflect"
"testing"
"github.com/actions/scaleset"
"github.com/go-logr/logr"
)
func Test_filterLabels(t *testing.T) {
type args struct {
labels map[string]string
filter string
}
tests := []struct {
name string
args args
want map[string]string
}{
{
name: "ok",
args: args{
labels: map[string]string{LabelKeyRunnerTemplateHash: "abc", LabelKeyPodTemplateHash: "def"},
filter: LabelKeyRunnerTemplateHash,
},
want: map[string]string{LabelKeyPodTemplateHash: "def"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FilterLabels(tt.args.labels, tt.args.filter); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FilterLabels() = %v, want %v", got, tt.want)
}
})
}
}
func Test_buildRunnerScaleSetLabels(t *testing.T) {
logger := logr.Discard()
tests := []struct {
name string
scaleSetName string
specLabels []string
want []scaleset.Label
}{
{
name: "name only, no extra labels",
scaleSetName: "my-runner",
specLabels: nil,
want: []scaleset.Label{
{Name: "my-runner", Type: "System"},
},
},
{
name: "name plus extra labels",
scaleSetName: "my-runner",
specLabels: []string{"linux", "x64"},
want: []scaleset.Label{
{Name: "my-runner", Type: "System"},
{Name: "linux", Type: "System"},
{Name: "x64", Type: "System"},
},
},
{
name: "deduplicates name from extra labels",
scaleSetName: "my-runner",
specLabels: []string{"my-runner", "linux"},
want: []scaleset.Label{
{Name: "my-runner", Type: "System"},
{Name: "linux", Type: "System"},
},
},
{
name: "deduplicates within extra labels",
scaleSetName: "my-runner",
specLabels: []string{"linux", "linux", "x64"},
want: []scaleset.Label{
{Name: "my-runner", Type: "System"},
{Name: "linux", Type: "System"},
{Name: "x64", Type: "System"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := buildRunnerScaleSetLabels(tt.scaleSetName, tt.specLabels, logger)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("buildRunnerScaleSetLabels() = %v, want %v", got, tt.want)
}
})
}
}
func Test_runnerScaleSetLabelsAnnotation(t *testing.T) {
tests := []struct {
name string
scaleSetName string
specLabels []string
want string
}{
{
name: "name only",
scaleSetName: "my-runner",
specLabels: nil,
want: "my-runner",
},
{
name: "sorted output",
scaleSetName: "my-runner",
specLabels: []string{"x64", "linux"},
want: "linux,my-runner,x64",
},
{
name: "deduplicates",
scaleSetName: "my-runner",
specLabels: []string{"my-runner", "linux"},
want: "linux,my-runner",
},
{
name: "stable regardless of input order",
scaleSetName: "my-runner",
specLabels: []string{"c", "a", "b"},
want: "a,b,c,my-runner",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := runnerScaleSetLabelsAnnotation(tt.scaleSetName, tt.specLabels)
if got != tt.want {
t.Errorf("runnerScaleSetLabelsAnnotation() = %q, want %q", got, tt.want)
}
})
}
}