Skip to content

Commit

Permalink
added test to catch creationTimestamp bug regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
killianmuldoon committed Nov 3, 2021
1 parent 47f39c2 commit 68948a1
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions internal/matchers/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand Down Expand Up @@ -179,6 +180,34 @@ func TestEqualObjectMatcher(t *testing.T) {
want: false,
},

// This tests specific behaviour in how Kubernetes marshals the zero value of metav1.Time{}.
{
name: "Creation timestamp set to empty value on both original and modified",
original: &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"A": "A",
},
"metadata": map[string]interface{}{
"selfLink": "foo",
"creationTimestamp": metav1.Time{},
},
},
},
modified: &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"A": "A",
},
"metadata": map[string]interface{}{
"selfLink": "foo",
"creationTimestamp": metav1.Time{},
},
},
},
want: true,
},

// Cases to test diff when fields exist only in modified object.
{
name: "Field only in modified",
Expand Down Expand Up @@ -212,6 +241,28 @@ func TestEqualObjectMatcher(t *testing.T) {
},
want: false,
},
{
name: "Creation timestamp exists on modified but not on original",
original: &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"A": "A",
},
},
},
modified: &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"A": "A",
},
"metadata": map[string]interface{}{
"selfLink": "foo",
"creationTimestamp": "2021-11-03T11:05:17Z",
},
},
},
want: false,
},

// Test when fields are exists only in the original object.
{
Expand Down Expand Up @@ -246,6 +297,29 @@ func TestEqualObjectMatcher(t *testing.T) {
},
want: false,
},
{
name: "Creation timestamp exists on original but not on modified",
original: &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"A": "A",
},
"metadata": map[string]interface{}{
"selfLink": "foo",
"creationTimestamp": "2021-11-03T11:05:17Z",
},
},
},
modified: &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"A": "A",
},
},
},

want: false,
},

// Test metadata fields computed by the system or in status are compared.
{
Expand Down

0 comments on commit 68948a1

Please sign in to comment.