Skip to content

Commit

Permalink
Fix flaky object mover test
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Feb 2, 2022
1 parent 236e6da commit 79a8c5a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions cmd/clusterctl/client/cluster/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,18 +653,32 @@ func Test_objectMover_backupTargetObject(t *testing.T) {

// Create an objectGraph bound a source cluster with all the CRDs for the types involved in the test.
graph := getObjectGraphWithObjs(tt.fields.objs)

// Get all the types to be considered for discovery
g.Expect(getFakeDiscoveryTypes(graph)).To(Succeed())

// trigger discovery the content of the source cluster
// Trigger discovery of the content of the source cluster.
g.Expect(graph.Discovery("")).To(Succeed())

// Run backupTargetObject on nodes in graph
// Create mover to run backupTargetObject on nodes in graph.
mover := objectMover{
fromProxy: graph.proxy,
}

// Create another mover with modified objects which we will use to test a second backup.
modifiedObjects := []client.Object{}
for _, o := range tt.fields.objs {
modifiedObject := o.DeepCopyObject().(client.Object)
modifiedObject.SetAnnotations(map[string]string{"object": "has been modified"})
modifiedObjects = append(modifiedObjects, modifiedObject)
}
modifiedGraph := getObjectGraphWithObjs(modifiedObjects)
// Get all the types to be considered for discovery
g.Expect(getFakeDiscoveryTypes(graph)).To(Succeed())
// Trigger discovery of the content of the source cluster.
g.Expect(modifiedGraph.Discovery("")).To(Succeed())
// Create a second mover to run backupTargetObject on nodes in graph with modified objects.
moverWithModifiedObjects := objectMover{
fromProxy: modifiedGraph.proxy,
}

dir, err := os.MkdirTemp("/tmp", "cluster-api")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -707,7 +721,7 @@ func Test_objectMover_backupTargetObject(t *testing.T) {
time.Sleep(time.Millisecond * 5)

// Running backupTargetObject should override any existing files since it represents a new backup
err = mover.backupTargetObject(node, dir)
err = moverWithModifiedObjects.backupTargetObject(node, dir)
if tt.wantErr {
g.Expect(err).To(HaveOccurred())
return
Expand Down

0 comments on commit 79a8c5a

Please sign in to comment.