sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/subnets_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 converters 18 19 import ( 20 "fmt" 21 "testing" 22 23 asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101" 24 . "github.com/onsi/gomega" 25 "k8s.io/utils/ptr" 26 ) 27 28 func TestGetSubnetAddresses(t *testing.T) { 29 tests := []struct { 30 name string 31 subnet asonetworkv1.VirtualNetworksSubnet 32 want []string 33 }{ 34 { 35 name: "nil", 36 subnet: asonetworkv1.VirtualNetworksSubnet{}, 37 }, 38 { 39 name: "subnet with single address prefix", 40 subnet: asonetworkv1.VirtualNetworksSubnet{ 41 Status: asonetworkv1.VirtualNetworks_Subnet_STATUS{ 42 AddressPrefix: ptr.To("test-address-prefix"), 43 }, 44 }, 45 want: []string{"test-address-prefix"}, 46 }, 47 { 48 name: "subnet with multiple address prefixes", 49 subnet: asonetworkv1.VirtualNetworksSubnet{ 50 Status: asonetworkv1.VirtualNetworks_Subnet_STATUS{ 51 AddressPrefixes: []string{ 52 "test-address-prefix-1", 53 "test-address-prefix-2", 54 }, 55 }, 56 }, 57 want: []string{"test-address-prefix-1", "test-address-prefix-2"}, 58 }, 59 } 60 for _, tt := range tests { 61 tt := tt 62 t.Run(tt.name, func(t *testing.T) { 63 t.Parallel() 64 g := NewGomegaWithT(t) 65 got := GetSubnetAddresses(tt.subnet) 66 g.Expect(got).To(Equal(tt.want), fmt.Sprintf("got: %v, want: %v", got, tt.want)) 67 }) 68 } 69 }