sigs.k8s.io/cluster-api-provider-azure@v1.17.0/util/reconciler/defaults_test.go (about) 1 /* 2 Copyright 2020 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 reconciler_test 18 19 import ( 20 "testing" 21 "time" 22 23 "github.com/onsi/gomega" 24 "sigs.k8s.io/cluster-api-provider-azure/util/reconciler" 25 ) 26 27 func TestDefaultedLoopTimeout(t *testing.T) { 28 cases := []struct { 29 Name string 30 Subject time.Duration 31 Expected time.Duration 32 }{ 33 { 34 Name: "WithZeroValueDefaults", 35 Subject: time.Duration(0), 36 Expected: reconciler.DefaultLoopTimeout, 37 }, 38 { 39 Name: "WithRealValue", 40 Subject: 2 * time.Hour, 41 Expected: 2 * time.Hour, 42 }, 43 { 44 Name: "WithNegativeValue", 45 Subject: time.Duration(-2), 46 Expected: reconciler.DefaultLoopTimeout, 47 }, 48 } 49 50 for _, c := range cases { 51 c := c 52 t.Run(c.Name, func(t *testing.T) { 53 t.Parallel() 54 g := gomega.NewWithT(t) 55 timeouts := reconciler.Timeouts{ 56 Loop: c.Subject, 57 } 58 g.Expect(timeouts.DefaultedLoopTimeout()).To(gomega.Equal(c.Expected)) 59 }) 60 } 61 } 62 63 func TestDefaultedReconcilerRequeue(t *testing.T) { 64 cases := []struct { 65 Name string 66 Subject time.Duration 67 Expected time.Duration 68 }{ 69 { 70 Name: "WithZeroValueDefaults", 71 Subject: time.Duration(0), 72 Expected: reconciler.DefaultReconcilerRequeue, 73 }, 74 { 75 Name: "WithRealValue", 76 Subject: 2 * time.Hour, 77 Expected: 2 * time.Hour, 78 }, 79 { 80 Name: "WithNegativeValue", 81 Subject: time.Duration(-2), 82 Expected: reconciler.DefaultReconcilerRequeue, 83 }, 84 } 85 86 for _, c := range cases { 87 c := c 88 t.Run(c.Name, func(t *testing.T) { 89 t.Parallel() 90 g := gomega.NewWithT(t) 91 timeouts := reconciler.Timeouts{ 92 Requeue: c.Subject, 93 } 94 g.Expect(timeouts.DefaultedReconcilerRequeue()).To(gomega.Equal(c.Expected)) 95 }) 96 } 97 } 98 99 func TestDefaultedAzureCallTimeout(t *testing.T) { 100 cases := []struct { 101 Name string 102 Subject time.Duration 103 Expected time.Duration 104 }{ 105 { 106 Name: "WithZeroValueDefaults", 107 Subject: time.Duration(0), 108 Expected: reconciler.DefaultAzureCallTimeout, 109 }, 110 { 111 Name: "WithRealValue", 112 Subject: 2 * time.Hour, 113 Expected: 2 * time.Hour, 114 }, 115 { 116 Name: "WithNegativeValue", 117 Subject: time.Duration(-2), 118 Expected: reconciler.DefaultAzureCallTimeout, 119 }, 120 } 121 122 for _, c := range cases { 123 c := c 124 t.Run(c.Name, func(t *testing.T) { 125 t.Parallel() 126 g := gomega.NewWithT(t) 127 timeouts := reconciler.Timeouts{ 128 AzureCall: c.Subject, 129 } 130 g.Expect(timeouts.DefaultedAzureCallTimeout()).To(gomega.Equal(c.Expected)) 131 }) 132 } 133 } 134 135 func TestDefaultedAzureServiceReconcileTimeout(t *testing.T) { 136 cases := []struct { 137 Name string 138 Subject time.Duration 139 Expected time.Duration 140 }{ 141 { 142 Name: "WithZeroValueDefaults", 143 Subject: time.Duration(0), 144 Expected: reconciler.DefaultAzureServiceReconcileTimeout, 145 }, 146 { 147 Name: "WithRealValue", 148 Subject: 2 * time.Hour, 149 Expected: 2 * time.Hour, 150 }, 151 { 152 Name: "WithNegativeValue", 153 Subject: time.Duration(-2), 154 Expected: reconciler.DefaultAzureServiceReconcileTimeout, 155 }, 156 } 157 158 for _, c := range cases { 159 c := c 160 t.Run(c.Name, func(t *testing.T) { 161 t.Parallel() 162 g := gomega.NewWithT(t) 163 timeouts := reconciler.Timeouts{ 164 AzureServiceReconcile: c.Subject, 165 } 166 g.Expect(timeouts.DefaultedAzureServiceReconcileTimeout()).To(gomega.Equal(c.Expected)) 167 }) 168 } 169 }