Skip to content

Commit b0a5526

Browse files
committed
refactored common in test
Signed-off-by: grokspawn <[email protected]>
1 parent 7ce873d commit b0a5526

File tree

1 file changed

+48
-170
lines changed

1 file changed

+48
-170
lines changed

pkg/controller/bundle/bundle_unpacker_test.go

Lines changed: 48 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,48 @@ func TestConfigMapUnpacker(t *testing.T) {
5959
customAnnotationDuration := 2 * time.Minute
6060
customAnnotationTimeoutSeconds := int64(customAnnotationDuration.Seconds())
6161

62+
podTolerations := []corev1.Toleration{
63+
// arch-specific tolerations
64+
{
65+
Key: "kubernetes.io/arch",
66+
Value: "amd64",
67+
Operator: "Equal",
68+
},
69+
{
70+
Key: "kubernetes.io/arch",
71+
Value: "arm64",
72+
Operator: "Equal",
73+
},
74+
{
75+
Key: "kubernetes.io/arch",
76+
Value: "ppc64le",
77+
Operator: "Equal",
78+
},
79+
{
80+
Key: "kubernetes.io/arch",
81+
Value: "s390x",
82+
Operator: "Equal",
83+
},
84+
// control-plane-specific tolerations
85+
{
86+
Key: "node-role.kubernetes.io/master",
87+
Operator: "Exists",
88+
Effect: "NoSchedule",
89+
},
90+
{
91+
Key: "node.kubernetes.io/unreachable",
92+
Operator: "Exists",
93+
Effect: "NoExecute",
94+
TolerationSeconds: ptr.To[int64](120),
95+
},
96+
{
97+
Key: "node.kubernetes.io/not-ready",
98+
Operator: "Exists",
99+
Effect: "NoExecute",
100+
TolerationSeconds: ptr.To[int64](120),
101+
},
102+
}
103+
62104
type fields struct {
63105
objs []runtime.Object
64106
crs []runtime.Object
@@ -345,47 +387,7 @@ func TestConfigMapUnpacker(t *testing.T) {
345387
NodeSelector: map[string]string{
346388
"kubernetes.io/os": "linux",
347389
},
348-
Tolerations: []corev1.Toleration{
349-
// arch-specific tolerations
350-
{
351-
Key: "kubernetes.io/arch",
352-
Value: "amd64",
353-
Operator: "Equal",
354-
},
355-
{
356-
Key: "kubernetes.io/arch",
357-
Value: "arm64",
358-
Operator: "Equal",
359-
},
360-
{
361-
Key: "kubernetes.io/arch",
362-
Value: "ppc64le",
363-
Operator: "Equal",
364-
},
365-
{
366-
Key: "kubernetes.io/arch",
367-
Value: "s390x",
368-
Operator: "Equal",
369-
},
370-
// control-plane-specific tolerations
371-
{
372-
Key: "node-role.kubernetes.io/master",
373-
Operator: "Exists",
374-
Effect: "NoSchedule",
375-
},
376-
{
377-
Key: "node.kubernetes.io/unreachable",
378-
Operator: "Exists",
379-
Effect: "NoExecute",
380-
TolerationSeconds: ptr.To[int64](120),
381-
},
382-
{
383-
Key: "node.kubernetes.io/not-ready",
384-
Operator: "Exists",
385-
Effect: "NoExecute",
386-
TolerationSeconds: ptr.To[int64](120),
387-
},
388-
},
390+
Tolerations: podTolerations,
389391
},
390392
},
391393
},
@@ -601,28 +603,7 @@ func TestConfigMapUnpacker(t *testing.T) {
601603
NodeSelector: map[string]string{
602604
"kubernetes.io/os": "linux",
603605
},
604-
Tolerations: []corev1.Toleration{
605-
{
606-
Key: "kubernetes.io/arch",
607-
Value: "amd64",
608-
Operator: "Equal",
609-
},
610-
{
611-
Key: "kubernetes.io/arch",
612-
Value: "arm64",
613-
Operator: "Equal",
614-
},
615-
{
616-
Key: "kubernetes.io/arch",
617-
Value: "ppc64le",
618-
Operator: "Equal",
619-
},
620-
{
621-
Key: "kubernetes.io/arch",
622-
Value: "s390x",
623-
Operator: "Equal",
624-
},
625-
},
606+
Tolerations: podTolerations,
626607
},
627608
},
628609
},
@@ -878,28 +859,7 @@ func TestConfigMapUnpacker(t *testing.T) {
878859
NodeSelector: map[string]string{
879860
"kubernetes.io/os": "linux",
880861
},
881-
Tolerations: []corev1.Toleration{
882-
{
883-
Key: "kubernetes.io/arch",
884-
Value: "amd64",
885-
Operator: "Equal",
886-
},
887-
{
888-
Key: "kubernetes.io/arch",
889-
Value: "arm64",
890-
Operator: "Equal",
891-
},
892-
{
893-
Key: "kubernetes.io/arch",
894-
Value: "ppc64le",
895-
Operator: "Equal",
896-
},
897-
{
898-
Key: "kubernetes.io/arch",
899-
Value: "s390x",
900-
Operator: "Equal",
901-
},
902-
},
862+
Tolerations: podTolerations,
903863
},
904864
},
905865
},
@@ -1150,47 +1110,7 @@ func TestConfigMapUnpacker(t *testing.T) {
11501110
NodeSelector: map[string]string{
11511111
"kubernetes.io/os": "linux",
11521112
},
1153-
Tolerations: []corev1.Toleration{
1154-
// arch-specific tolerations
1155-
{
1156-
Key: "kubernetes.io/arch",
1157-
Value: "amd64",
1158-
Operator: "Equal",
1159-
},
1160-
{
1161-
Key: "kubernetes.io/arch",
1162-
Value: "arm64",
1163-
Operator: "Equal",
1164-
},
1165-
{
1166-
Key: "kubernetes.io/arch",
1167-
Value: "ppc64le",
1168-
Operator: "Equal",
1169-
},
1170-
{
1171-
Key: "kubernetes.io/arch",
1172-
Value: "s390x",
1173-
Operator: "Equal",
1174-
},
1175-
// control-plane-specific tolerations
1176-
{
1177-
Key: "node-role.kubernetes.io/master",
1178-
Operator: "Exists",
1179-
Effect: "NoSchedule",
1180-
},
1181-
{
1182-
Key: "node.kubernetes.io/unreachable",
1183-
Operator: "Exists",
1184-
Effect: "NoExecute",
1185-
TolerationSeconds: ptr.To[int64](120),
1186-
},
1187-
{
1188-
Key: "node.kubernetes.io/not-ready",
1189-
Operator: "Exists",
1190-
Effect: "NoExecute",
1191-
TolerationSeconds: ptr.To[int64](120),
1192-
},
1193-
},
1113+
Tolerations: podTolerations,
11941114
},
11951115
},
11961116
},
@@ -1411,28 +1331,7 @@ func TestConfigMapUnpacker(t *testing.T) {
14111331
NodeSelector: map[string]string{
14121332
"kubernetes.io/os": "linux",
14131333
},
1414-
Tolerations: []corev1.Toleration{
1415-
{
1416-
Key: "kubernetes.io/arch",
1417-
Value: "amd64",
1418-
Operator: "Equal",
1419-
},
1420-
{
1421-
Key: "kubernetes.io/arch",
1422-
Value: "arm64",
1423-
Operator: "Equal",
1424-
},
1425-
{
1426-
Key: "kubernetes.io/arch",
1427-
Value: "ppc64le",
1428-
Operator: "Equal",
1429-
},
1430-
{
1431-
Key: "kubernetes.io/arch",
1432-
Value: "s390x",
1433-
Operator: "Equal",
1434-
},
1435-
},
1334+
Tolerations: podTolerations,
14361335
},
14371336
},
14381337
},
@@ -1666,28 +1565,7 @@ func TestConfigMapUnpacker(t *testing.T) {
16661565
NodeSelector: map[string]string{
16671566
"kubernetes.io/os": "linux",
16681567
},
1669-
Tolerations: []corev1.Toleration{
1670-
{
1671-
Key: "kubernetes.io/arch",
1672-
Value: "amd64",
1673-
Operator: "Equal",
1674-
},
1675-
{
1676-
Key: "kubernetes.io/arch",
1677-
Value: "arm64",
1678-
Operator: "Equal",
1679-
},
1680-
{
1681-
Key: "kubernetes.io/arch",
1682-
Value: "ppc64le",
1683-
Operator: "Equal",
1684-
},
1685-
{
1686-
Key: "kubernetes.io/arch",
1687-
Value: "s390x",
1688-
Operator: "Equal",
1689-
},
1690-
},
1568+
Tolerations: podTolerations,
16911569
},
16921570
},
16931571
},

0 commit comments

Comments
 (0)