sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/diagnostics_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 "testing" 21 22 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" 23 "github.com/google/go-cmp/cmp" 24 "k8s.io/utils/ptr" 25 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 26 ) 27 28 func TestGetDiagnosticsProfile(t *testing.T) { 29 tests := []struct { 30 name string 31 diagnostics *infrav1.Diagnostics 32 want *armcompute.DiagnosticsProfile 33 }{ 34 { 35 name: "managed diagnostics", 36 diagnostics: &infrav1.Diagnostics{ 37 Boot: &infrav1.BootDiagnostics{ 38 StorageAccountType: infrav1.ManagedDiagnosticsStorage, 39 }, 40 }, 41 want: &armcompute.DiagnosticsProfile{ 42 BootDiagnostics: &armcompute.BootDiagnostics{ 43 Enabled: ptr.To(true), 44 }, 45 }, 46 }, 47 { 48 name: "user managed diagnostics", 49 diagnostics: &infrav1.Diagnostics{ 50 Boot: &infrav1.BootDiagnostics{ 51 StorageAccountType: infrav1.UserManagedDiagnosticsStorage, 52 UserManaged: &infrav1.UserManagedBootDiagnostics{ 53 StorageAccountURI: "https://fake", 54 }, 55 }, 56 }, 57 want: &armcompute.DiagnosticsProfile{ 58 BootDiagnostics: &armcompute.BootDiagnostics{ 59 Enabled: ptr.To(true), 60 StorageURI: ptr.To("https://fake"), 61 }, 62 }, 63 }, 64 { 65 name: "disabled diagnostics", 66 diagnostics: &infrav1.Diagnostics{ 67 Boot: &infrav1.BootDiagnostics{ 68 StorageAccountType: infrav1.DisabledDiagnosticsStorage, 69 }, 70 }, 71 want: &armcompute.DiagnosticsProfile{ 72 BootDiagnostics: &armcompute.BootDiagnostics{ 73 Enabled: ptr.To(false), 74 }, 75 }, 76 }, 77 { 78 name: "nil diagnostics boot", 79 diagnostics: &infrav1.Diagnostics{ 80 Boot: nil, 81 }, 82 want: nil, 83 }, 84 } 85 for _, tt := range tests { 86 tt := tt 87 t.Run(tt.name, func(t *testing.T) { 88 t.Parallel() 89 got := GetDiagnosticsProfile(tt.diagnostics) 90 if diff := cmp.Diff(tt.want, got); diff != "" { 91 t.Errorf("GetDiagnosticsProfile(%s) mismatch (-want +got):\n%s", tt.name, diff) 92 } 93 }) 94 } 95 }