Skip to content

Commit fb205c3

Browse files
committed
WIP: refactor haveacm fn
Pass only the runtime client instead of the whole reconciler object. This makes the testing also cleaner a bit.
1 parent 5384935 commit fb205c3

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

internal/controller/acm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var mchGVK = schema.GroupVersionKind{
3535
Version: "v1",
3636
}
3737

38-
func haveACMHub(r *PatternReconciler) bool {
38+
func haveACMHub(cl client.Client) bool {
3939
labelSelector, err := labels.Parse(fmt.Sprintf("%v = %v", "ocm-configmap-type", "image-manifest"))
4040

4141
if err != nil {
@@ -44,7 +44,7 @@ func haveACMHub(r *PatternReconciler) bool {
4444
}
4545

4646
cms := corev1.ConfigMapList{}
47-
err = r.List(context.Background(), &cms, &client.ListOptions{
47+
err = cl.List(context.Background(), &cms, &client.ListOptions{
4848
LabelSelector: labelSelector,
4949
})
5050

@@ -61,7 +61,7 @@ func haveACMHub(r *PatternReconciler) bool {
6161
umch := &unstructured.UnstructuredList{}
6262
umch.SetGroupVersionKind(mchGVK)
6363

64-
err = r.List(context.Background(), umch, &client.ListOptions{Namespace: ns})
64+
err = cl.List(context.Background(), umch, &client.ListOptions{Namespace: ns})
6565

6666
if err != nil {
6767
log.Printf("Error obtaining hub: %s\n", err)

internal/controller/acm_test.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ import (
1919
var _ = Describe("HaveACMHub", func() {
2020

2121
var (
22-
patternReconciler *PatternReconciler
23-
fakeClient client.Client
24-
configMap *v1.ConfigMap
25-
hub *unstructured.Unstructured
22+
fakeClient client.Client
23+
configMap *v1.ConfigMap
24+
hub *unstructured.Unstructured
2625
)
2726
BeforeEach(func() {
2827
configMap = &v1.ConfigMap{
@@ -51,11 +50,8 @@ var _ = Describe("HaveACMHub", func() {
5150
It("should return true", func() {
5251
fakeClient = fake.NewClientBuilder().WithScheme(testEnv.Scheme).
5352
WithRuntimeObjects(configMap, hub).Build()
54-
patternReconciler = &PatternReconciler{
55-
Client: fakeClient,
56-
}
5753

58-
result := haveACMHub(patternReconciler)
54+
result := haveACMHub(fakeClient)
5955
Expect(result).To(BeTrue())
6056
})
6157
})
@@ -66,11 +62,8 @@ var _ = Describe("HaveACMHub", func() {
6662

6763
fakeClient = fake.NewClientBuilder().WithScheme(testEnv.Scheme).
6864
WithRuntimeObjects(configMap, hub).Build()
69-
patternReconciler = &PatternReconciler{
70-
Client: fakeClient,
71-
}
7265

73-
result := haveACMHub(patternReconciler)
66+
result := haveACMHub(fakeClient)
7467
Expect(result).To(BeFalse())
7568
})
7669
})
@@ -79,11 +72,8 @@ var _ = Describe("HaveACMHub", func() {
7972
It("should return false", func() {
8073
fakeClient = fake.NewClientBuilder().WithScheme(testEnv.Scheme).
8174
WithRuntimeObjects().Build()
82-
patternReconciler = &PatternReconciler{
83-
Client: fakeClient,
84-
}
8575

86-
result := haveACMHub(patternReconciler)
76+
result := haveACMHub(fakeClient)
8777
Expect(result).To(BeFalse())
8878
})
8979
})
@@ -95,11 +85,7 @@ var _ = Describe("HaveACMHub", func() {
9585
return fmt.Errorf("list error")
9686
}}).WithScheme(testEnv.Scheme).Build()
9787

98-
patternReconciler = &PatternReconciler{
99-
Client: fakeClient,
100-
}
101-
102-
result := haveACMHub(patternReconciler)
88+
result := haveACMHub(fakeClient)
10389
Expect(result).To(BeFalse())
10490
})
10591
})
@@ -111,11 +97,7 @@ var _ = Describe("HaveACMHub", func() {
11197
return fmt.Errorf("list error")
11298
}}).WithScheme(testEnv.Scheme).WithRuntimeObjects(configMap).Build()
11399

114-
patternReconciler = &PatternReconciler{
115-
Client: fakeClient,
116-
}
117-
118-
result := haveACMHub(patternReconciler)
100+
result := haveACMHub(fakeClient)
119101
Expect(result).To(BeFalse())
120102
})
121103
})

internal/controller/pattern_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
571571
return fmt.Errorf("updated application %q for removal", app.Name)
572572
}
573573

574-
if haveACMHub(r) {
574+
if haveACMHub(r.Client) {
575575
return fmt.Errorf("waiting for removal of that acm hub")
576576
}
577577

0 commit comments

Comments
 (0)