From cb7ea5d6215ab2e68554be9a4fa0ee67e18ead16 Mon Sep 17 00:00:00 2001 From: Cavaughn Browne Date: Tue, 21 Feb 2023 17:52:15 -0600 Subject: [PATCH] add error case to unit test --- pkg/cluster/cloudstack_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/cluster/cloudstack_test.go b/pkg/cluster/cloudstack_test.go index e8b7b6c9607fa..a7250a1a70498 100644 --- a/pkg/cluster/cloudstack_test.go +++ b/pkg/cluster/cloudstack_test.go @@ -2,6 +2,7 @@ package cluster_test import ( "context" + "errors" "testing" "github.com/golang/mock/gomock" @@ -54,6 +55,14 @@ func TestDefaultConfigClientBuilderCloudStackCluster(t *testing.T) { Namespace: "default", }, } + + wantError := errors.New("test error") + + client.EXPECT().Get(ctx, "datacenter", "default", &anywherev1.CloudStackDatacenterConfig{}).Return(wantError) + + _, err := b.Build(ctx, client, cluster) + g.Expect(err).To(MatchError(ContainSubstring("building Config from a cluster client"))) + client.EXPECT().Get(ctx, "datacenter", "default", &anywherev1.CloudStackDatacenterConfig{}).Return(nil).DoAndReturn( func(ctx context.Context, name, namespace string, obj runtime.Object) error { d := obj.(*anywherev1.CloudStackDatacenterConfig)