Skip to content

Commit 23f5a14

Browse files
author
Harvey Lowndes
committed
Add unit tests
1 parent 0f670fa commit 23f5a14

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

pkg/oci/load_balancer_spec_test.go

+171
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,177 @@ func TestNewLBSpecSuccess(t *testing.T) {
311311
securityListManager: newSecurityListManagerNOOP(),
312312
},
313313
},
314+
"protocol annotation set to http": {
315+
defaultSubnetOne: "one",
316+
defaultSubnetTwo: "two",
317+
service: &v1.Service{
318+
ObjectMeta: metav1.ObjectMeta{
319+
Namespace: "kube-system",
320+
Name: "testservice",
321+
UID: "test-uid",
322+
Annotations: map[string]string{
323+
ServiceAnnotationLoadBalancerBEProtocol: "HTTP",
324+
ServiceAnnotationLoadBalancerSubnet1: "annotation-one",
325+
ServiceAnnotationLoadBalancerSubnet2: "annotation-two",
326+
},
327+
},
328+
Spec: v1.ServiceSpec{
329+
SessionAffinity: v1.ServiceAffinityNone,
330+
Ports: []v1.ServicePort{
331+
v1.ServicePort{
332+
Protocol: v1.ProtocolTCP,
333+
Port: int32(80),
334+
},
335+
},
336+
},
337+
},
338+
expected: &LBSpec{
339+
Name: "test-uid",
340+
Shape: "100Mbps",
341+
Internal: false,
342+
Subnets: []string{"annotation-one", "annotation-two"},
343+
Listeners: map[string]loadbalancer.ListenerDetails{
344+
"HTTP-80": loadbalancer.ListenerDetails{
345+
DefaultBackendSetName: common.String("TCP-80"),
346+
Port: common.Int(80),
347+
Protocol: common.String("HTTP"),
348+
},
349+
},
350+
BackendSets: map[string]loadbalancer.BackendSetDetails{
351+
"TCP-80": loadbalancer.BackendSetDetails{
352+
Backends: []loadbalancer.BackendDetails{},
353+
HealthChecker: &loadbalancer.HealthCheckerDetails{
354+
Protocol: common.String("HTTP"),
355+
Port: common.Int(10256),
356+
UrlPath: common.String("/healthz"),
357+
},
358+
Policy: common.String("ROUND_ROBIN"),
359+
},
360+
},
361+
SourceCIDRs: []string{"0.0.0.0/0"},
362+
Ports: map[string]portSpec{
363+
"TCP-80": portSpec{
364+
ListenerPort: 80,
365+
HealthCheckerPort: 10256,
366+
},
367+
},
368+
securityListManager: newSecurityListManagerNOOP(),
369+
},
370+
},
371+
"protocol annotation set to tcp": {
372+
defaultSubnetOne: "one",
373+
defaultSubnetTwo: "two",
374+
service: &v1.Service{
375+
ObjectMeta: metav1.ObjectMeta{
376+
Namespace: "kube-system",
377+
Name: "testservice",
378+
UID: "test-uid",
379+
Annotations: map[string]string{
380+
ServiceAnnotationLoadBalancerBEProtocol: "TCP",
381+
ServiceAnnotationLoadBalancerSubnet1: "annotation-one",
382+
ServiceAnnotationLoadBalancerSubnet2: "annotation-two",
383+
},
384+
},
385+
Spec: v1.ServiceSpec{
386+
SessionAffinity: v1.ServiceAffinityNone,
387+
Ports: []v1.ServicePort{
388+
v1.ServicePort{
389+
Protocol: v1.ProtocolTCP,
390+
Port: int32(80),
391+
},
392+
},
393+
},
394+
},
395+
expected: &LBSpec{
396+
Name: "test-uid",
397+
Shape: "100Mbps",
398+
Internal: false,
399+
Subnets: []string{"annotation-one", "annotation-two"},
400+
Listeners: map[string]loadbalancer.ListenerDetails{
401+
"TCP-80": loadbalancer.ListenerDetails{
402+
DefaultBackendSetName: common.String("TCP-80"),
403+
Port: common.Int(80),
404+
Protocol: common.String("TCP"),
405+
},
406+
},
407+
BackendSets: map[string]loadbalancer.BackendSetDetails{
408+
"TCP-80": loadbalancer.BackendSetDetails{
409+
Backends: []loadbalancer.BackendDetails{},
410+
HealthChecker: &loadbalancer.HealthCheckerDetails{
411+
Protocol: common.String("HTTP"),
412+
Port: common.Int(10256),
413+
UrlPath: common.String("/healthz"),
414+
},
415+
Policy: common.String("ROUND_ROBIN"),
416+
},
417+
},
418+
SourceCIDRs: []string{"0.0.0.0/0"},
419+
Ports: map[string]portSpec{
420+
"TCP-80": portSpec{
421+
ListenerPort: 80,
422+
HealthCheckerPort: 10256,
423+
},
424+
},
425+
securityListManager: newSecurityListManagerNOOP(),
426+
},
427+
},
428+
"protocol annotation empty": {
429+
defaultSubnetOne: "one",
430+
defaultSubnetTwo: "two",
431+
service: &v1.Service{
432+
ObjectMeta: metav1.ObjectMeta{
433+
Namespace: "kube-system",
434+
Name: "testservice",
435+
UID: "test-uid",
436+
Annotations: map[string]string{
437+
ServiceAnnotationLoadBalancerBEProtocol: "",
438+
ServiceAnnotationLoadBalancerSubnet1: "annotation-one",
439+
ServiceAnnotationLoadBalancerSubnet2: "annotation-two",
440+
},
441+
},
442+
Spec: v1.ServiceSpec{
443+
SessionAffinity: v1.ServiceAffinityNone,
444+
Ports: []v1.ServicePort{
445+
v1.ServicePort{
446+
Protocol: v1.ProtocolTCP,
447+
Port: int32(80),
448+
},
449+
},
450+
},
451+
},
452+
expected: &LBSpec{
453+
Name: "test-uid",
454+
Shape: "100Mbps",
455+
Internal: false,
456+
Subnets: []string{"annotation-one", "annotation-two"},
457+
Listeners: map[string]loadbalancer.ListenerDetails{
458+
"TCP-80": loadbalancer.ListenerDetails{
459+
DefaultBackendSetName: common.String("TCP-80"),
460+
Port: common.Int(80),
461+
Protocol: common.String("TCP"),
462+
},
463+
},
464+
BackendSets: map[string]loadbalancer.BackendSetDetails{
465+
"TCP-80": loadbalancer.BackendSetDetails{
466+
Backends: []loadbalancer.BackendDetails{},
467+
HealthChecker: &loadbalancer.HealthCheckerDetails{
468+
Protocol: common.String("HTTP"),
469+
Port: common.Int(10256),
470+
UrlPath: common.String("/healthz"),
471+
},
472+
Policy: common.String("ROUND_ROBIN"),
473+
},
474+
},
475+
SourceCIDRs: []string{"0.0.0.0/0"},
476+
Ports: map[string]portSpec{
477+
"TCP-80": portSpec{
478+
ListenerPort: 80,
479+
HealthCheckerPort: 10256,
480+
},
481+
},
482+
securityListManager: newSecurityListManagerNOOP(),
483+
},
484+
},
314485
}
315486

316487
for name, tc := range testCases {

0 commit comments

Comments
 (0)