Skip to content

Commit 9d6d7d2

Browse files
committed
update mock function
Signed-off-by: rashmi_kh <[email protected]>
1 parent b503a40 commit 9d6d7d2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

internal/controllers/clusterextension_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/operator-framework/operator-registry/alpha/declcfg"
2929

3030
ocv1 "github.com/operator-framework/operator-controller/api/v1"
31+
3132
"github.com/operator-framework/operator-controller/internal/authentication"
3233
"github.com/operator-framework/operator-controller/internal/conditionsets"
3334
"github.com/operator-framework/operator-controller/internal/controllers"
@@ -334,11 +335,10 @@ func TestClusterExtensionResolutionAndUnpackSuccessfulApplierFails(t *testing.T)
334335
}
335336

336337
func TestClusterExtensionServiceAccountNotFound(t *testing.T) {
337-
cl, reconciler := newClientAndReconciler(t, func(r *controllers.ClusterExtensionReconciler) {
338-
r.InstalledBundleGetter = &MockInstalledBundleGetter{
339-
err: &authentication.ServiceAccountNotFoundError{}, // Simulate missing SA
340-
}
341-
})
338+
cl, reconciler := newClientAndReconciler(t)
339+
reconciler.InstalledBundleGetter = &MockInstalledBundleGetter{
340+
err: &authentication.ServiceAccountNotFoundError{}, // Simulate missing SA
341+
}
342342

343343
ctx := context.Background()
344344
extKey := types.NamespacedName{Name: fmt.Sprintf("cluster-extension-test-%s", rand.String(8))}

internal/controllers/suite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ func newClient(t *testing.T) client.Client {
7474

7575
type MockInstalledBundleGetter struct {
7676
bundle *controllers.InstalledBundle
77+
err error
7778
}
7879

7980
func (m *MockInstalledBundleGetter) SetBundle(bundle *controllers.InstalledBundle) {
8081
m.bundle = bundle
8182
}
8283

8384
func (m *MockInstalledBundleGetter) GetInstalledBundle(ctx context.Context, ext *ocv1.ClusterExtension) (*controllers.InstalledBundle, error) {
85+
if m.err != nil {
86+
return nil, m.err
87+
}
8488
return m.bundle, nil
8589
}
8690

0 commit comments

Comments
 (0)