@@ -25,6 +25,7 @@ import (
25
25
"github.com/Azure/go-autorest/autorest/to"
26
26
"github.com/stretchr/testify/assert"
27
27
"k8s.io/api/core/v1"
28
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
29
)
29
30
30
31
func TestFindProbe (t * testing.T ) {
@@ -243,3 +244,67 @@ func TestGetIdleTimeout(t *testing.T) {
243
244
})
244
245
}
245
246
}
247
+
248
+ func TestSubnet (t * testing.T ) {
249
+ for i , c := range []struct {
250
+ desc string
251
+ service * v1.Service
252
+ expected * string
253
+ }{
254
+ {
255
+ desc : "No annotation should return nil" ,
256
+ service : & v1.Service {},
257
+ expected : nil ,
258
+ },
259
+ {
260
+ desc : "annotation with subnet but no ILB should return nil" ,
261
+ service : & v1.Service {
262
+ ObjectMeta : metav1.ObjectMeta {
263
+ Annotations : map [string ]string {
264
+ ServiceAnnotationLoadBalancerInternalSubnet : "subnet" ,
265
+ },
266
+ },
267
+ },
268
+ expected : nil ,
269
+ },
270
+ {
271
+ desc : "annotation with subnet but ILB=false should return nil" ,
272
+ service : & v1.Service {
273
+ ObjectMeta : metav1.ObjectMeta {
274
+ Annotations : map [string ]string {
275
+ ServiceAnnotationLoadBalancerInternalSubnet : "subnet" ,
276
+ ServiceAnnotationLoadBalancerInternal : "false" ,
277
+ },
278
+ },
279
+ },
280
+ expected : nil ,
281
+ },
282
+ {
283
+ desc : "annotation with empty subnet should return nil" ,
284
+ service : & v1.Service {
285
+ ObjectMeta : metav1.ObjectMeta {
286
+ Annotations : map [string ]string {
287
+ ServiceAnnotationLoadBalancerInternalSubnet : "" ,
288
+ ServiceAnnotationLoadBalancerInternal : "true" ,
289
+ },
290
+ },
291
+ },
292
+ expected : nil ,
293
+ },
294
+ {
295
+ desc : "annotation with subnet and ILB should return subnet" ,
296
+ service : & v1.Service {
297
+ ObjectMeta : metav1.ObjectMeta {
298
+ Annotations : map [string ]string {
299
+ ServiceAnnotationLoadBalancerInternalSubnet : "subnet" ,
300
+ ServiceAnnotationLoadBalancerInternal : "true" ,
301
+ },
302
+ },
303
+ },
304
+ expected : to .StringPtr ("subnet" ),
305
+ },
306
+ } {
307
+ real := subnet (c .service )
308
+ assert .Equal (t , c .expected , real , fmt .Sprintf ("TestCase[%d]: %s" , i , c .desc ))
309
+ }
310
+ }
0 commit comments