sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/resourcehealth_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/resourcehealth/armresourcehealth" 23 . "github.com/onsi/gomega" 24 corev1 "k8s.io/api/core/v1" 25 "k8s.io/utils/ptr" 26 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 27 ) 28 29 func TestAzureAvailabilityStatusToCondition(t *testing.T) { 30 tests := []struct { 31 name string 32 avail armresourcehealth.AvailabilityStatus 33 expected *clusterv1.Condition 34 }{ 35 { 36 name: "empty", 37 avail: armresourcehealth.AvailabilityStatus{}, 38 expected: &clusterv1.Condition{ 39 Status: corev1.ConditionFalse, 40 }, 41 }, 42 { 43 name: "available", 44 avail: armresourcehealth.AvailabilityStatus{ 45 Properties: &armresourcehealth.AvailabilityStatusProperties{ 46 AvailabilityState: ptr.To(armresourcehealth.AvailabilityStateValuesAvailable), 47 }, 48 }, 49 expected: &clusterv1.Condition{ 50 Status: corev1.ConditionTrue, 51 }, 52 }, 53 { 54 name: "unavailable", 55 avail: armresourcehealth.AvailabilityStatus{ 56 Properties: &armresourcehealth.AvailabilityStatusProperties{ 57 AvailabilityState: ptr.To(armresourcehealth.AvailabilityStateValuesUnavailable), 58 ReasonType: ptr.To("this Is a reason "), 59 Summary: ptr.To("The Summary"), 60 }, 61 }, 62 expected: &clusterv1.Condition{ 63 Status: corev1.ConditionFalse, 64 Severity: clusterv1.ConditionSeverityError, 65 Reason: "ThisIsAReason", 66 Message: "The Summary", 67 }, 68 }, 69 { 70 name: "degraded", 71 avail: armresourcehealth.AvailabilityStatus{ 72 Properties: &armresourcehealth.AvailabilityStatusProperties{ 73 AvailabilityState: ptr.To(armresourcehealth.AvailabilityStateValuesDegraded), 74 ReasonType: ptr.To("TheReason"), 75 Summary: ptr.To("The Summary"), 76 }, 77 }, 78 expected: &clusterv1.Condition{ 79 Status: corev1.ConditionFalse, 80 Severity: clusterv1.ConditionSeverityWarning, 81 Reason: "TheReason", 82 Message: "The Summary", 83 }, 84 }, 85 } 86 87 for _, test := range tests { 88 test := test 89 t.Run(test.name, func(t *testing.T) { 90 g := NewWithT(t) 91 t.Parallel() 92 93 cond := SDKAvailabilityStatusToCondition(test.avail) 94 95 g.Expect(cond.Status).To(Equal(test.expected.Status)) 96 g.Expect(cond.Severity).To(Equal(test.expected.Severity)) 97 g.Expect(cond.Reason).To(Equal(test.expected.Reason)) 98 g.Expect(cond.Message).To(Equal(test.expected.Message)) 99 }) 100 } 101 }