Skip to content

Commit

Permalink
add error case to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cxbrowne1207 committed Feb 21, 2023
1 parent 60ab96b commit cb7ea5d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/cluster/cloudstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cluster_test

import (
"context"
"errors"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cb7ea5d

Please sign in to comment.