Skip to content

Commit

Permalink
Add spec test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Dec 11, 2021
1 parent 1bf2594 commit e62291f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion azure/services/availabilitysets/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
Expand Down
70 changes: 70 additions & 0 deletions azure/services/availabilitysets/spec_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit e62291f

Please sign in to comment.