@@ -9,13 +9,11 @@ import (
9
9
)
10
10
11
11
func TestNodeCondition (t * testing.T ) {
12
- testTable := []struct {
13
- Name string
12
+ testTable := map [string ]struct {
14
13
Node * corev1.Node
15
14
Expected string
16
15
}{
17
- {
18
- Name : "Basic Node" ,
16
+ "Basic Case" : {
19
17
Node : & corev1.Node {
20
18
Status : corev1.NodeStatus {
21
19
Conditions : []corev1.NodeCondition {
@@ -30,21 +28,21 @@ func TestNodeCondition(t *testing.T) {
30
28
},
31
29
}
32
30
33
- for _ , tc := range testTable {
34
- actual := nodeCondition (* tc .Node )
35
- assert .Equal (t , tc .Expected , actual , "fail" )
31
+ for name , tc := range testTable {
32
+ t .Run (name , func (t * testing.T ) {
33
+ actual := nodeCondition (* tc .Node )
34
+ assert .Equal (t , tc .Expected , actual , "failed" )
35
+ })
36
36
}
37
37
}
38
38
39
39
func TestNodepoolLabels (t * testing.T ) {
40
- testTable := []struct {
41
- Name string
40
+ testTable := map [string ]struct {
42
41
Node * corev1.Node
43
42
CustomLabel string
44
43
Expected string
45
44
}{
46
- {
47
- Name : "Basic Node - No matching label" ,
45
+ "no matching label" : {
48
46
Node : & corev1.Node {
49
47
ObjectMeta : v1.ObjectMeta {
50
48
Labels : map [string ]string {
@@ -54,8 +52,7 @@ func TestNodepoolLabels(t *testing.T) {
54
52
},
55
53
Expected : "-" ,
56
54
},
57
- {
58
- Name : "Basic Node - Custom Label" ,
55
+ "custom label" : {
59
56
Node : & corev1.Node {
60
57
ObjectMeta : v1.ObjectMeta {
61
58
Labels : map [string ]string {
@@ -66,8 +63,7 @@ func TestNodepoolLabels(t *testing.T) {
66
63
CustomLabel : "custom-label" ,
67
64
Expected : "custom label" ,
68
65
},
69
- {
70
- Name : "Basic Node - AWS" ,
66
+ "AWS" : {
71
67
Node : & corev1.Node {
72
68
ObjectMeta : v1.ObjectMeta {
73
69
Labels : map [string ]string {
@@ -77,8 +73,7 @@ func TestNodepoolLabels(t *testing.T) {
77
73
},
78
74
Expected : "test AWS" ,
79
75
},
80
- {
81
- Name : "Basic Node - GCP" ,
76
+ "GCP" : {
82
77
Node : & corev1.Node {
83
78
ObjectMeta : v1.ObjectMeta {
84
79
Labels : map [string ]string {
@@ -88,8 +83,7 @@ func TestNodepoolLabels(t *testing.T) {
88
83
},
89
84
Expected : "test GCP" ,
90
85
},
91
- {
92
- Name : "Basic Node - AKS" ,
86
+ "AKS" : {
93
87
Node : & corev1.Node {
94
88
ObjectMeta : v1.ObjectMeta {
95
89
Labels : map [string ]string {
@@ -99,8 +93,7 @@ func TestNodepoolLabels(t *testing.T) {
99
93
},
100
94
Expected : "test AKS" ,
101
95
},
102
- {
103
- Name : "Basic Node - DigitalOcean" ,
96
+ "DigitalOcean" : {
104
97
Node : & corev1.Node {
105
98
ObjectMeta : v1.ObjectMeta {
106
99
Labels : map [string ]string {
@@ -110,8 +103,7 @@ func TestNodepoolLabels(t *testing.T) {
110
103
},
111
104
Expected : "test DigitalOcean" ,
112
105
},
113
- {
114
- Name : "Basic Node, v1alpha5" ,
106
+ "v1alpha5 API" : {
115
107
Node : & corev1.Node {
116
108
ObjectMeta : v1.ObjectMeta {
117
109
Labels : map [string ]string {
@@ -121,8 +113,7 @@ func TestNodepoolLabels(t *testing.T) {
121
113
},
122
114
Expected : "(Karpenter) test v1alpha5" ,
123
115
},
124
- {
125
- Name : "Basic Node, v1beta1" ,
116
+ "v1beta1 API" : {
126
117
Node : & corev1.Node {
127
118
ObjectMeta : v1.ObjectMeta {
128
119
Labels : map [string ]string {
@@ -134,8 +125,10 @@ func TestNodepoolLabels(t *testing.T) {
134
125
},
135
126
}
136
127
137
- for _ , tc := range testTable {
138
- actual := findNodepool (* tc .Node , tc .CustomLabel )
139
- assert .Equal (t , tc .Expected , actual , "fail" )
128
+ for name , tc := range testTable {
129
+ t .Run (name , func (t * testing.T ) {
130
+ actual := findNodepool (* tc .Node , tc .CustomLabel )
131
+ assert .Equal (t , tc .Expected , actual , "failed" )
132
+ })
140
133
}
141
134
}
0 commit comments