sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/extendedlocation_test.go (about) 1 /* 2 Copyright 2023 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 "reflect" 21 "testing" 22 23 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" 24 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4" 25 asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101" 26 "k8s.io/utils/ptr" 27 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 28 ) 29 30 func TestExtendedLocationToNetworkSDK(t *testing.T) { 31 tests := []struct { 32 name string 33 args *infrav1.ExtendedLocationSpec 34 want *armnetwork.ExtendedLocation 35 }{ 36 { 37 name: "normal extendedLocation instance", 38 args: &infrav1.ExtendedLocationSpec{ 39 Name: "value", 40 Type: "EdgeZone", 41 }, 42 want: &armnetwork.ExtendedLocation{ 43 Name: ptr.To("value"), 44 Type: ptr.To(armnetwork.ExtendedLocationTypesEdgeZone), 45 }, 46 }, 47 { 48 name: "nil extendedLocation properties", 49 args: nil, 50 want: nil, 51 }, 52 } 53 for _, tt := range tests { 54 t.Run(tt.name, func(t *testing.T) { 55 if got := ExtendedLocationToNetworkSDK(tt.args); !reflect.DeepEqual(got, tt.want) { 56 t.Errorf("ExtendedLocationToNetworkSDK() = %v, want %v", got, tt.want) 57 } 58 }) 59 } 60 } 61 62 func TestExtendedLocationToNetworkASO(t *testing.T) { 63 tests := []struct { 64 name string 65 args *infrav1.ExtendedLocationSpec 66 want *asonetworkv1.ExtendedLocation 67 }{ 68 { 69 name: "normal extendedLocation instance", 70 args: &infrav1.ExtendedLocationSpec{ 71 Name: "value", 72 Type: "EdgeZone", 73 }, 74 want: &asonetworkv1.ExtendedLocation{ 75 Name: ptr.To("value"), 76 Type: ptr.To(asonetworkv1.ExtendedLocationType_EdgeZone), 77 }, 78 }, 79 { 80 name: "nil extendedLocation properties", 81 args: nil, 82 want: nil, 83 }, 84 } 85 for _, tt := range tests { 86 t.Run(tt.name, func(t *testing.T) { 87 if got := ExtendedLocationToNetworkASO(tt.args); !reflect.DeepEqual(got, tt.want) { 88 t.Errorf("ExtendedLocationToNetworkASO() = %v, want %v", got, tt.want) 89 } 90 }) 91 } 92 } 93 94 func TestExtendedLocationToComputeSDK(t *testing.T) { 95 tests := []struct { 96 name string 97 args *infrav1.ExtendedLocationSpec 98 want *armcompute.ExtendedLocation 99 }{ 100 { 101 name: "normal extendedLocation instance", 102 args: &infrav1.ExtendedLocationSpec{ 103 Name: "value", 104 Type: "Edge", 105 }, 106 want: &armcompute.ExtendedLocation{ 107 Name: ptr.To("value"), 108 Type: ptr.To(armcompute.ExtendedLocationTypes("Edge")), 109 }, 110 }, 111 { 112 name: "nil extendedLocation properties", 113 args: nil, 114 want: nil, 115 }, 116 } 117 for _, tt := range tests { 118 t.Run(tt.name, func(t *testing.T) { 119 if got := ExtendedLocationToComputeSDK(tt.args); !reflect.DeepEqual(got, tt.want) { 120 t.Errorf("ExtendedLocationToComputeSDK() = %v, want %v", got, tt.want) 121 } 122 }) 123 } 124 }