Skip to content

Commit bc04ec7

Browse files
committed
services/availabilityzones: add test to check the spec
1 parent e490b54 commit bc04ec7

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cloud/services/availabilityzones/availabilityzones_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/Azure/go-autorest/autorest/to"
3030
"github.com/golang/mock/gomock"
3131

32+
network "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
3233
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3334
"k8s.io/client-go/kubernetes/scheme"
3435
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
@@ -42,12 +43,29 @@ func init() {
4243
}
4344

4445
const (
45-
subscriptionID = "123"
46+
expectedInvalidSpec = "invalid availability zones specification"
47+
subscriptionID = "123"
4648
)
4749

48-
func TestGetAvailabilityZones(t *testing.T) {
50+
func TestInvalidAvailabilityZonesSpec(t *testing.T) {
4951
g := NewWithT(t)
5052

53+
mockCtrl := gomock.NewController(t)
54+
agentpoolsMock := mock_availabilityzones.NewMockClient(mockCtrl)
55+
56+
s := &Service{
57+
Client: agentpoolsMock,
58+
}
59+
60+
// Wrong Spec
61+
wrongSpec := &network.LoadBalancer{}
62+
63+
_, err := s.Get(context.TODO(), &wrongSpec)
64+
g.Expect(err).To(HaveOccurred())
65+
g.Expect(err).To(MatchError(expectedInvalidSpec))
66+
}
67+
68+
func TestGetAvailabilityZones(t *testing.T) {
5169
testcases := []struct {
5270
name string
5371
availabilityZoneSpec Spec
@@ -98,6 +116,8 @@ func TestGetAvailabilityZones(t *testing.T) {
98116

99117
for _, tc := range testcases {
100118
t.Run(tc.name, func(t *testing.T) {
119+
g := NewWithT(t)
120+
101121
mockCtrl := gomock.NewController(t)
102122
azMock := mock_availabilityzones.NewMockClient(mockCtrl)
103123

0 commit comments

Comments
 (0)