-
Notifications
You must be signed in to change notification settings - Fork 15
/
constraints_test.go
62 lines (58 loc) · 1.59 KB
/
constraints_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
package cke
import "testing"
func testConstraintsCheck(t *testing.T) {
nodes := []*Node{
{ControlPlane: true},
{ControlPlane: true},
{ControlPlane: false},
{ControlPlane: false},
}
tests := []struct {
name string
constraints Constraints
cluster Cluster
wantErr bool
}{
{
name: "valid case",
constraints: Constraints{ControlPlaneCount: 2, MaximumWorkers: 2, MinimumWorkers: 1},
cluster: Cluster{Nodes: nodes[:]},
wantErr: false,
},
{
name: "maximum 0 means unlimited",
constraints: Constraints{ControlPlaneCount: 2, MaximumWorkers: 0, MinimumWorkers: 1},
cluster: Cluster{Nodes: nodes[:]},
wantErr: false,
},
{
name: "control plane not equal",
constraints: Constraints{ControlPlaneCount: 1, MaximumWorkers: 2, MinimumWorkers: 1},
cluster: Cluster{Nodes: nodes[:]},
wantErr: true,
},
{
name: "too many workers",
constraints: Constraints{ControlPlaneCount: 2, MaximumWorkers: 1, MinimumWorkers: 1},
cluster: Cluster{Nodes: nodes[:]},
wantErr: true,
},
{
name: "too few workers",
constraints: Constraints{ControlPlaneCount: 2, MaximumWorkers: 6, MinimumWorkers: 2},
cluster: Cluster{Nodes: nodes[:2]},
wantErr: true,
},
}
for _, tt := range tests {
c := tt.constraints
t.Run(tt.name, func(t *testing.T) {
if err := c.Check(&tt.cluster); (err != nil) != tt.wantErr {
t.Errorf("Constraints.Check() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestConstraints(t *testing.T) {
t.Run("Check", testConstraintsCheck)
}