Skip to content

Commit

Permalink
Extend unit tests to cover preservation of cluster ID label
Browse files Browse the repository at this point in the history
...after transformation in the resourceSyncer.

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Aug 16, 2023
1 parent 814f827 commit 2451712
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pkg/syncer/resource_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func testRemoteToLocalWithoutLocalClusterID() {
}

func testTransformFunction() {
d := newTestDriver(test.LocalNamespace, "", syncer.LocalToRemote)
d := newTestDriver(test.LocalNamespace, "", syncer.RemoteToLocal)
ctx := context.TODO()

var transformed *corev1.Pod
Expand All @@ -336,6 +336,7 @@ func testTransformFunction() {
var requeue bool

BeforeEach(func() {
test.SetClusterIDLabel(d.resource, "remote")
atomic.StoreInt32(&invocationCount, 0)
expOperation = make(chan syncer.Operation, 20)
transformed = test.NewPodWithImage(d.config.SourceNamespace, "transformed")
Expand All @@ -353,13 +354,21 @@ func testTransformFunction() {
}
})

verifyDistribute := func() {
d.federator.VerifyDistribute(test.SetClusterIDLabel(test.ToUnstructured(transformed), "remote"))
}

verifyDelete := func() {
d.federator.VerifyDelete(test.SetClusterIDLabel(test.ToUnstructured(transformed), "remote"))
}

When("a resource is created in the datastore", func() {
JustBeforeEach(func() {
test.CreateResource(d.sourceClient, d.resource)
})

It("should distribute the transformed resource", func() {
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))
Consistently(func() int {
return int(atomic.LoadInt32(&invocationCount))
Expand All @@ -385,7 +394,7 @@ func testTransformFunction() {
})

It("should distribute the transformed resource", func() {
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))

d.resource = test.NewPodWithImage(d.config.SourceNamespace, "updated")
Expand All @@ -401,14 +410,14 @@ func testTransformFunction() {
})

JustBeforeEach(func() {
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))
atomic.StoreInt32(&invocationCount, 0)
})

It("should delete the transformed resource", func() {
Expect(d.sourceClient.Delete(ctx, d.resource.GetName(), metav1.DeleteOptions{})).To(Succeed())
d.federator.VerifyDelete(test.ToUnstructured(transformed))
verifyDelete()
Eventually(expOperation).Should(Receive(Equal(syncer.Delete)))
Consistently(func() int {
return int(atomic.LoadInt32(&invocationCount))
Expand Down Expand Up @@ -436,11 +445,11 @@ func testTransformFunction() {
})

It("should retry until it succeeds", func() {
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))

Expect(d.sourceClient.Delete(ctx, d.resource.GetName(), metav1.DeleteOptions{})).To(Succeed())
d.federator.VerifyDelete(test.ToUnstructured(transformed))
verifyDelete()
Eventually(expOperation).Should(Receive(Equal(syncer.Delete)))
Eventually(expOperation).Should(Receive(Equal(syncer.Delete)))
})
Expand All @@ -453,7 +462,7 @@ func testTransformFunction() {

It("retry until it succeeds", func() {
test.CreateResource(d.sourceClient, d.resource)
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))
})
Expand Down Expand Up @@ -518,7 +527,7 @@ func testTransformFunction() {
Context("and a resource is created in the datastore", func() {
It("should eventually distribute the transformed resource", func() {
test.CreateResource(d.sourceClient, d.resource)
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))
})
})
Expand All @@ -529,12 +538,12 @@ func testTransformFunction() {
})

It("should eventually delete the resource", func() {
d.federator.VerifyDistribute(test.ToUnstructured(transformed))
verifyDistribute()
Eventually(expOperation).Should(Receive(Equal(syncer.Create)))
transformFuncRet.Store(nilResource)

Expect(d.sourceClient.Delete(ctx, d.resource.GetName(), metav1.DeleteOptions{})).To(Succeed())
d.federator.VerifyDelete(test.ToUnstructured(transformed))
verifyDelete()
Eventually(expOperation).Should(Receive(Equal(syncer.Delete)))
})
})
Expand Down

0 comments on commit 2451712

Please sign in to comment.