From e62291f539b4da2be406a738d8d2d78a258f3885 Mon Sep 17 00:00:00 2001 From: Jonathan Tong Date: Fri, 10 Dec 2021 17:26:33 -0800 Subject: [PATCH] Add spec test --- azure/services/availabilitysets/spec.go | 3 +- azure/services/availabilitysets/spec_test.go | 70 ++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 azure/services/availabilitysets/spec_test.go diff --git a/azure/services/availabilitysets/spec.go b/azure/services/availabilitysets/spec.go index 68d139cf907..66de91b1e6a 100644 --- a/azure/services/availabilitysets/spec.go +++ b/azure/services/availabilitysets/spec.go @@ -63,7 +63,8 @@ func (s *AvailabilitySetSpec) Parameters(existing interface{}) (interface{}, err return nil, errors.New("unable to find required FaultDomainCount from machine cache") } - asParams := &compute.AvailabilitySet{ + asParams := compute.AvailabilitySet{ + // TODO: should availability sets be given a name? Sku: &compute.Sku{ Name: to.StringPtr(string(compute.AvailabilitySetSkuTypesAligned)), }, diff --git a/azure/services/availabilitysets/spec_test.go b/azure/services/availabilitysets/spec_test.go new file mode 100644 index 00000000000..1d53c0f45b7 --- /dev/null +++ b/azure/services/availabilitysets/spec_test.go @@ -0,0 +1,70 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package availabilitysets + +import ( + "testing" + + "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-04-01/compute" + . "github.com/onsi/gomega" +) + +func TestParameters(t *testing.T) { + testcases := []struct { + name string + spec *AvailabilitySetSpec + existing interface{} + expect func(g *WithT, result interface{}) + expectedError string + }{ + { + name: "error when no fault domain count is present", + spec: &fakeSetSpecMissing, + existing: nil, + expect: func(g *WithT, result interface{}) { + g.Expect(result).To(BeNil()) + }, + expectedError: "unable to find required FaultDomainCount from machine cache", + }, + { + name: "get parameters when all values are present", + spec: &fakeSetSpec, + existing: nil, + expect: func(g *WithT, result interface{}) { + g.Expect(result).To(BeAssignableToTypeOf(compute.AvailabilitySet{})) + g.Expect(result.(compute.AvailabilitySet).PlatformFaultDomainCount).To(Equal(fakeSetSpec.FaultDomainCount)) + }, + expectedError: "", + }, + } + for _, tc := range testcases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + t.Parallel() + + result, err := tc.spec.Parameters(tc.existing) + if tc.expectedError != "" { + g.Expect(err).To(HaveOccurred()) + g.Expect(err).To(MatchError(tc.expectedError)) + } else { + g.Expect(err).NotTo(HaveOccurred()) + } + tc.expect(g, result) + }) + } +}