Skip to content

Commit 68948a1

Browse files
added test to catch creationTimestamp bug regressions
1 parent 47f39c2 commit 68948a1

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

internal/matchers/matchers_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/gomega"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2425
)
2526

@@ -179,6 +180,34 @@ func TestEqualObjectMatcher(t *testing.T) {
179180
want: false,
180181
},
181182

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+
182211
// Cases to test diff when fields exist only in modified object.
183212
{
184213
name: "Field only in modified",
@@ -212,6 +241,28 @@ func TestEqualObjectMatcher(t *testing.T) {
212241
},
213242
want: false,
214243
},
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+
},
215266

216267
// Test when fields are exists only in the original object.
217268
{
@@ -246,6 +297,29 @@ func TestEqualObjectMatcher(t *testing.T) {
246297
},
247298
want: false,
248299
},
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+
},
249323

250324
// Test metadata fields computed by the system or in status are compared.
251325
{

0 commit comments

Comments
 (0)