5
5
6
6
corev1 "k8s.io/api/core/v1"
7
7
"k8s.io/apimachinery/pkg/api/equality"
8
+ "k8s.io/apimachinery/pkg/util/diff"
8
9
"k8s.io/utils/pointer"
9
10
)
10
11
@@ -16,14 +17,98 @@ func TestEnsurePodSpec(t *testing.T) {
16
17
17
18
expectedModified bool
18
19
expected corev1.PodSpec
19
- }{{
20
- name : "empty inputs" ,
21
- existing : corev1.PodSpec {},
22
- input : corev1.PodSpec {},
20
+ }{
21
+ {
22
+ name : "empty inputs" ,
23
+ existing : corev1.PodSpec {},
24
+ input : corev1.PodSpec {},
23
25
24
- expectedModified : false ,
25
- expected : corev1.PodSpec {},
26
- }}
26
+ expectedModified : false ,
27
+ expected : corev1.PodSpec {},
28
+ },
29
+ {
30
+ name : "remove regular containers from existing" ,
31
+ existing : corev1.PodSpec {
32
+ Containers : []corev1.Container {
33
+ corev1.Container {Name : "test" }}},
34
+ input : corev1.PodSpec {},
35
+
36
+ expectedModified : true ,
37
+ expected : corev1.PodSpec {},
38
+ },
39
+ {
40
+ name : "remove regular and init containers from existing" ,
41
+ existing : corev1.PodSpec {
42
+ InitContainers : []corev1.Container {
43
+ corev1.Container {Name : "test-init" }},
44
+ Containers : []corev1.Container {
45
+ corev1.Container {Name : "test" }}},
46
+ input : corev1.PodSpec {},
47
+
48
+ expectedModified : true ,
49
+ expected : corev1.PodSpec {},
50
+ },
51
+ {
52
+ name : "remove init containers from existing" ,
53
+ existing : corev1.PodSpec {
54
+ InitContainers : []corev1.Container {
55
+ corev1.Container {Name : "test-init" }}},
56
+ input : corev1.PodSpec {},
57
+
58
+ expectedModified : true ,
59
+ expected : corev1.PodSpec {},
60
+ },
61
+ {
62
+ name : "append regular and init containers" ,
63
+ existing : corev1.PodSpec {
64
+ InitContainers : []corev1.Container {
65
+ corev1.Container {Name : "test-init-a" }},
66
+ Containers : []corev1.Container {
67
+ corev1.Container {Name : "test-a" }}},
68
+ input : corev1.PodSpec {
69
+ InitContainers : []corev1.Container {
70
+ corev1.Container {Name : "test-init-a" },
71
+ corev1.Container {Name : "test-init-b" },
72
+ },
73
+ Containers : []corev1.Container {
74
+ corev1.Container {Name : "test-a" },
75
+ corev1.Container {Name : "test-b" },
76
+ },
77
+ },
78
+
79
+ expectedModified : true ,
80
+ expected : corev1.PodSpec {
81
+ InitContainers : []corev1.Container {
82
+ corev1.Container {Name : "test-init-a" },
83
+ corev1.Container {Name : "test-init-b" },
84
+ },
85
+ Containers : []corev1.Container {
86
+ corev1.Container {Name : "test-a" },
87
+ corev1.Container {Name : "test-b" },
88
+ },
89
+ },
90
+ },
91
+ {
92
+ name : "match regular and init containers" ,
93
+ existing : corev1.PodSpec {
94
+ InitContainers : []corev1.Container {
95
+ corev1.Container {Name : "test-init" }},
96
+ Containers : []corev1.Container {
97
+ corev1.Container {Name : "test" }}},
98
+ input : corev1.PodSpec {
99
+ InitContainers : []corev1.Container {
100
+ corev1.Container {Name : "test-init" }},
101
+ Containers : []corev1.Container {
102
+ corev1.Container {Name : "test" }}},
103
+
104
+ expectedModified : false ,
105
+ expected : corev1.PodSpec {
106
+ InitContainers : []corev1.Container {
107
+ corev1.Container {Name : "test-init" }},
108
+ Containers : []corev1.Container {
109
+ corev1.Container {Name : "test" }}},
110
+ },
111
+ }
27
112
28
113
for _ , test := range tests {
29
114
t .Run (test .name , func (t * testing.T ) {
@@ -34,7 +119,7 @@ func TestEnsurePodSpec(t *testing.T) {
34
119
}
35
120
36
121
if ! equality .Semantic .DeepEqual (test .existing , test .expected ) {
37
- t .Errorf ("mismatch PodSpec got : %v want: %v " , test .existing , test .expected )
122
+ t .Errorf ("unexpected : %s " , diff . ObjectReflectDiff ( test .expected , test .existing ) )
38
123
}
39
124
})
40
125
}
0 commit comments