Skip to content

Commit

Permalink
remove adding List for discoveryType in test
Browse files Browse the repository at this point in the history
remove getFakeDiscoveryTypes and directly use graph.getDiscoveryTypes

fix provider namespace secret not included in clusterclt move
  • Loading branch information
archerwu9425 committed Nov 21, 2023
1 parent 3d3dcc6 commit 327b470
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
22 changes: 11 additions & 11 deletions cmd/clusterctl/client/cluster/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func Test_objectMover_backupTargetObject(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -826,7 +826,7 @@ func Test_objectMover_restoreTargetObject(t *testing.T) {
graph := getObjectGraph()

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -934,7 +934,7 @@ func Test_objectMover_toDirectory(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func Test_objectMover_fromDirectory(t *testing.T) {
graph := getObjectGraph()

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

// gets a fakeProxy to an empty cluster with all the required CRDs
toProxy := getFakeProxyWithCRDs()
Expand Down Expand Up @@ -1155,7 +1155,7 @@ func Test_getMoveSequence(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -1188,7 +1188,7 @@ func Test_objectMover_move_dryRun(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -1263,7 +1263,7 @@ func Test_objectMover_move(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -1375,7 +1375,7 @@ func Test_objectMover_move_with_Mutator(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -1660,7 +1660,7 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -1906,7 +1906,7 @@ func Test_objectMoverService_ensureNamespaces(t *testing.T) {
graph := getObjectGraphWithObjs(tt.fields.objs)

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

// Trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down Expand Up @@ -2385,7 +2385,7 @@ func TestWaitReadyForMove(t *testing.T) {
}

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

// trigger discovery the content of the source cluster
g.Expect(graph.Discovery(ctx, "")).To(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/objectgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (o *objectGraph) Discovery(ctx context.Context, namespace string) error {
}

// if we are discovering Secrets, also secrets from the providers namespace should be included.
if discoveryType.typeMeta.GetObjectKind().GroupVersionKind().GroupKind() == corev1.SchemeGroupVersion.WithKind("SecretList").GroupKind() {
if discoveryType.typeMeta.GetObjectKind().GroupVersionKind().GroupKind() == corev1.SchemeGroupVersion.WithKind("Secret").GroupKind() {
providers, err := o.providerInventory.List(ctx)
if err != nil {
return err
Expand Down
16 changes: 2 additions & 14 deletions cmd/clusterctl/client/cluster/objectgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1774,18 +1774,6 @@ func getFakeProxyWithCRDs() *test.FakeProxy {
return proxy
}

func getFakeDiscoveryTypes(ctx context.Context, graph *objectGraph) error {
if err := graph.getDiscoveryTypes(ctx); err != nil {
return err
}

// Given that the Fake client behaves in a different way than real client, for this test we are required to add the List suffix to all the types.
for _, discoveryType := range graph.types {
discoveryType.typeMeta.Kind = fmt.Sprintf("%sList", discoveryType.typeMeta.Kind)
}
return nil
}

func TestObjectGraph_Discovery(t *testing.T) {
// NB. we are testing the graph is properly built starting from objects (TestGraphBuilder_addObj_WithFakeObjects) or from the same objects read from the cluster (this test).
for _, tt := range objectGraphsTests {
Expand All @@ -1798,7 +1786,7 @@ func TestObjectGraph_Discovery(t *testing.T) {
graph := getObjectGraphWithObjs(tt.args.objs)

// Get all the types to be considered for discovery
err := getFakeDiscoveryTypes(ctx, graph)
err := graph.getDiscoveryTypes(ctx)
g.Expect(err).ToNot(HaveOccurred())

// finally test discovery
Expand Down Expand Up @@ -1956,7 +1944,7 @@ func TestObjectGraph_DiscoveryByNamespace(t *testing.T) {
graph := getObjectGraphWithObjs(tt.args.objs)

// Get all the types to be considered for discovery
err := getFakeDiscoveryTypes(ctx, graph)
err := graph.getDiscoveryTypes(ctx)
g.Expect(err).ToNot(HaveOccurred())

// finally test discovery
Expand Down

0 comments on commit 327b470

Please sign in to comment.