sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/scalesets/vmssextension_spec_test.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package scalesets 18 19 import ( 20 "context" 21 "testing" 22 23 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" 24 . "github.com/onsi/gomega" 25 "k8s.io/utils/ptr" 26 "sigs.k8s.io/cluster-api-provider-azure/azure" 27 ) 28 29 var ( 30 fakeVMSSExtensionSpec = VMSSExtensionSpec{ 31 azure.ExtensionSpec{ 32 Name: "my-vm-extension", 33 VMName: "my-vm", 34 Publisher: "my-publisher", 35 Version: "1.0", 36 Settings: map[string]string{"my-setting": "my-value"}, 37 ProtectedSettings: map[string]string{"my-protected-setting": "my-protected-value"}, 38 }, 39 "my-rg", 40 } 41 42 fakeVMSSExtensionParams = armcompute.VirtualMachineScaleSetExtension{ 43 Name: ptr.To("my-vm-extension"), 44 Properties: &armcompute.VirtualMachineScaleSetExtensionProperties{ 45 Publisher: ptr.To("my-publisher"), 46 Type: ptr.To("my-vm-extension"), 47 TypeHandlerVersion: ptr.To("1.0"), 48 Settings: map[string]string{"my-setting": "my-value"}, 49 ProtectedSettings: map[string]string{"my-protected-setting": "my-protected-value"}, 50 }, 51 } 52 ) 53 54 func TestVMSSExtensionParameters(t *testing.T) { 55 testcases := []struct { 56 name string 57 spec *VMSSExtensionSpec 58 existing interface{} 59 expect func(g *WithT, result interface{}) 60 expectedError string 61 }{ 62 { 63 name: "get parameters for vmextension", 64 spec: &fakeVMSSExtensionSpec, 65 existing: nil, 66 expect: func(g *WithT, result interface{}) { 67 g.Expect(result).To(Equal(fakeVMSSExtensionParams)) 68 }, 69 expectedError: "", 70 }, 71 { 72 name: "vmextension that already exists", 73 spec: &fakeVMSSExtensionSpec, 74 existing: fakeVMSSExtensionParams, 75 expect: func(g *WithT, result interface{}) { 76 g.Expect(result).To(BeNil()) 77 }, 78 expectedError: "", 79 }, 80 } 81 for _, tc := range testcases { 82 tc := tc 83 t.Run(tc.name, func(t *testing.T) { 84 g := NewWithT(t) 85 t.Parallel() 86 87 result, err := tc.spec.Parameters(context.TODO(), tc.existing) 88 if tc.expectedError != "" { 89 g.Expect(err).To(HaveOccurred()) 90 g.Expect(err).To(MatchError(tc.expectedError)) 91 } else { 92 g.Expect(err).NotTo(HaveOccurred()) 93 } 94 tc.expect(g, result) 95 }) 96 } 97 }