Skip to content

Commit 3198b92

Browse files
committed
updating testing format
1 parent 03570d0 commit 3198b92

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

main_test.go

+21-28
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import (
99
)
1010

1111
func TestNodeCondition(t *testing.T) {
12-
testTable := []struct {
13-
Name string
12+
testTable := map[string]struct {
1413
Node *corev1.Node
1514
Expected string
1615
}{
17-
{
18-
Name: "Basic Node",
16+
"Basic Case": {
1917
Node: &corev1.Node{
2018
Status: corev1.NodeStatus{
2119
Conditions: []corev1.NodeCondition{
@@ -30,21 +28,21 @@ func TestNodeCondition(t *testing.T) {
3028
},
3129
}
3230

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+
})
3636
}
3737
}
3838

3939
func TestNodepoolLabels(t *testing.T) {
40-
testTable := []struct {
41-
Name string
40+
testTable := map[string]struct {
4241
Node *corev1.Node
4342
CustomLabel string
4443
Expected string
4544
}{
46-
{
47-
Name: "Basic Node - No matching label",
45+
"no matching label": {
4846
Node: &corev1.Node{
4947
ObjectMeta: v1.ObjectMeta{
5048
Labels: map[string]string{
@@ -54,8 +52,7 @@ func TestNodepoolLabels(t *testing.T) {
5452
},
5553
Expected: "-",
5654
},
57-
{
58-
Name: "Basic Node - Custom Label",
55+
"custom label": {
5956
Node: &corev1.Node{
6057
ObjectMeta: v1.ObjectMeta{
6158
Labels: map[string]string{
@@ -66,8 +63,7 @@ func TestNodepoolLabels(t *testing.T) {
6663
CustomLabel: "custom-label",
6764
Expected: "custom label",
6865
},
69-
{
70-
Name: "Basic Node - AWS",
66+
"AWS": {
7167
Node: &corev1.Node{
7268
ObjectMeta: v1.ObjectMeta{
7369
Labels: map[string]string{
@@ -77,8 +73,7 @@ func TestNodepoolLabels(t *testing.T) {
7773
},
7874
Expected: "test AWS",
7975
},
80-
{
81-
Name: "Basic Node - GCP",
76+
"GCP": {
8277
Node: &corev1.Node{
8378
ObjectMeta: v1.ObjectMeta{
8479
Labels: map[string]string{
@@ -88,8 +83,7 @@ func TestNodepoolLabels(t *testing.T) {
8883
},
8984
Expected: "test GCP",
9085
},
91-
{
92-
Name: "Basic Node - AKS",
86+
"AKS": {
9387
Node: &corev1.Node{
9488
ObjectMeta: v1.ObjectMeta{
9589
Labels: map[string]string{
@@ -99,8 +93,7 @@ func TestNodepoolLabels(t *testing.T) {
9993
},
10094
Expected: "test AKS",
10195
},
102-
{
103-
Name: "Basic Node - DigitalOcean",
96+
"DigitalOcean": {
10497
Node: &corev1.Node{
10598
ObjectMeta: v1.ObjectMeta{
10699
Labels: map[string]string{
@@ -110,8 +103,7 @@ func TestNodepoolLabels(t *testing.T) {
110103
},
111104
Expected: "test DigitalOcean",
112105
},
113-
{
114-
Name: "Basic Node, v1alpha5",
106+
"v1alpha5 API": {
115107
Node: &corev1.Node{
116108
ObjectMeta: v1.ObjectMeta{
117109
Labels: map[string]string{
@@ -121,8 +113,7 @@ func TestNodepoolLabels(t *testing.T) {
121113
},
122114
Expected: "(Karpenter) test v1alpha5",
123115
},
124-
{
125-
Name: "Basic Node, v1beta1",
116+
"v1beta1 API": {
126117
Node: &corev1.Node{
127118
ObjectMeta: v1.ObjectMeta{
128119
Labels: map[string]string{
@@ -134,8 +125,10 @@ func TestNodepoolLabels(t *testing.T) {
134125
},
135126
}
136127

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+
})
140133
}
141134
}

0 commit comments

Comments
 (0)