Skip to content

Commit

Permalink
Initialize gomega locally to each t.Run()
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed May 12, 2021
1 parent 529c457 commit d2faf48
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions util/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import (

func TestPatchHelper(t *testing.T) {
t.Run("should patch an unstructured object", func(t *testing.T) {
g := NewWithT(t)

obj := &unstructured.Unstructured{
Object: map[string]interface{}{
"kind": "BootstrapMachine",
Expand All @@ -51,6 +49,8 @@ func TestPatchHelper(t *testing.T) {
}

t.Run("adding an owner reference, preserving its status", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the unstructured object")
Expand Down Expand Up @@ -109,9 +109,9 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("Should patch conditions", func(t *testing.T) {
g := NewWithT(t)

t.Run("on a corev1.Node object", func(t *testing.T) {
g := NewWithT(t)

conditionTime := metav1.Date(2015, 1, 1, 12, 0, 0, 0, metav1.Now().Location())

obj := &corev1.Node{
Expand Down Expand Up @@ -168,8 +168,6 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("on a clusterv1.Cluster object", func(t *testing.T) {
g := NewWithT(t)

obj := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-",
Expand All @@ -178,6 +176,8 @@ func TestPatchHelper(t *testing.T) {
}

t.Run("should mark it ready", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -217,6 +217,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("should recover if there is a resolvable conflict", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -272,6 +274,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("should recover if there is a resolvable conflict, incl. patch spec and status", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -334,6 +338,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("should return an error if there is an unresolvable conflict", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -383,6 +389,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("should not return an error if there is an unresolvable conflict but the conditions is owned by the controller", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -435,6 +443,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("should not return an error if there is an unresolvable conflict when force overwrite is enabled", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -489,16 +499,16 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("Should patch a clusterv1.Cluster", func(t *testing.T) {
g := NewWithT(t)

obj := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-",
Namespace: "default",
},
}

t.Run("add a finalizers", func(t *testing.T) {
t.Run("add a finalizer", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -539,6 +549,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("removing finalizers", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()
obj.Finalizers = append(obj.Finalizers, clusterv1.ClusterFinalizer)

Expand Down Expand Up @@ -580,6 +592,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("updating spec", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()
obj.ObjectMeta.Namespace = "default"

Expand Down Expand Up @@ -627,6 +641,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("updating status", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the object")
Expand Down Expand Up @@ -666,6 +682,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("updating both spec, status, and adding a condition", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()
obj.ObjectMeta.Namespace = "default"

Expand Down Expand Up @@ -721,8 +739,6 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("Should update Status.ObservedGeneration when using WithStatusObservedGeneration option", func(t *testing.T) {
g := NewWithT(t)

obj := &clusterv1.MachineSet{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-ms",
Expand All @@ -739,6 +755,8 @@ func TestPatchHelper(t *testing.T) {
}

t.Run("when updating spec", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the MachineSet object")
Expand Down Expand Up @@ -780,6 +798,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("when updating spec, status, and metadata", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the MachineSet object")
Expand Down Expand Up @@ -831,6 +851,8 @@ func TestPatchHelper(t *testing.T) {
})

t.Run("without any changes", func(t *testing.T) {
g := NewWithT(t)

obj := obj.DeepCopy()

t.Log("Creating the MachineSet object")
Expand Down

0 comments on commit d2faf48

Please sign in to comment.