@@ -20,6 +20,7 @@ import (
20
20
"testing"
21
21
22
22
. "github.com/onsi/gomega"
23
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
24
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24
25
)
25
26
@@ -179,6 +180,34 @@ func TestEqualObjectMatcher(t *testing.T) {
179
180
want : false ,
180
181
},
181
182
183
+ // This tests specific behaviour in how Kubernetes marshals the zero value of metav1.Time{}.
184
+ {
185
+ name : "Creation timestamp set to empty value on both original and modified" ,
186
+ original : & unstructured.Unstructured {
187
+ Object : map [string ]interface {}{
188
+ "spec" : map [string ]interface {}{
189
+ "A" : "A" ,
190
+ },
191
+ "metadata" : map [string ]interface {}{
192
+ "selfLink" : "foo" ,
193
+ "creationTimestamp" : metav1.Time {},
194
+ },
195
+ },
196
+ },
197
+ modified : & unstructured.Unstructured {
198
+ Object : map [string ]interface {}{
199
+ "spec" : map [string ]interface {}{
200
+ "A" : "A" ,
201
+ },
202
+ "metadata" : map [string ]interface {}{
203
+ "selfLink" : "foo" ,
204
+ "creationTimestamp" : metav1.Time {},
205
+ },
206
+ },
207
+ },
208
+ want : true ,
209
+ },
210
+
182
211
// Cases to test diff when fields exist only in modified object.
183
212
{
184
213
name : "Field only in modified" ,
@@ -212,6 +241,28 @@ func TestEqualObjectMatcher(t *testing.T) {
212
241
},
213
242
want : false ,
214
243
},
244
+ {
245
+ name : "Creation timestamp exists on modified but not on original" ,
246
+ original : & unstructured.Unstructured {
247
+ Object : map [string ]interface {}{
248
+ "spec" : map [string ]interface {}{
249
+ "A" : "A" ,
250
+ },
251
+ },
252
+ },
253
+ modified : & unstructured.Unstructured {
254
+ Object : map [string ]interface {}{
255
+ "spec" : map [string ]interface {}{
256
+ "A" : "A" ,
257
+ },
258
+ "metadata" : map [string ]interface {}{
259
+ "selfLink" : "foo" ,
260
+ "creationTimestamp" : "2021-11-03T11:05:17Z" ,
261
+ },
262
+ },
263
+ },
264
+ want : false ,
265
+ },
215
266
216
267
// Test when fields are exists only in the original object.
217
268
{
@@ -246,6 +297,29 @@ func TestEqualObjectMatcher(t *testing.T) {
246
297
},
247
298
want : false ,
248
299
},
300
+ {
301
+ name : "Creation timestamp exists on original but not on modified" ,
302
+ original : & unstructured.Unstructured {
303
+ Object : map [string ]interface {}{
304
+ "spec" : map [string ]interface {}{
305
+ "A" : "A" ,
306
+ },
307
+ "metadata" : map [string ]interface {}{
308
+ "selfLink" : "foo" ,
309
+ "creationTimestamp" : "2021-11-03T11:05:17Z" ,
310
+ },
311
+ },
312
+ },
313
+ modified : & unstructured.Unstructured {
314
+ Object : map [string ]interface {}{
315
+ "spec" : map [string ]interface {}{
316
+ "A" : "A" ,
317
+ },
318
+ },
319
+ },
320
+
321
+ want : false ,
322
+ },
249
323
250
324
// Test metadata fields computed by the system or in status are compared.
251
325
{
0 commit comments