Commit 2ab36816 authored by Zihong Zheng's avatar Zihong Zheng

Fix-up and add unit test for Load Balancer finalizer

parent aa3f81d6
......@@ -20,7 +20,8 @@ import (
"strings"
"testing"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilnet "k8s.io/utils/net"
)
......@@ -219,3 +220,52 @@ func TestNeedsHealthCheck(t *testing.T) {
},
})
}
func TestHasLBFinalizer(t *testing.T) {
testCases := []struct {
desc string
svc *v1.Service
hasFinalizer bool
}{
{
desc: "service without finalizer",
svc: &v1.Service{},
hasFinalizer: false,
},
{
desc: "service with unrelated finalizer",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{"unrelated"},
},
},
hasFinalizer: false,
},
{
desc: "service with one finalizer",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{LoadBalancerCleanupFinalizer},
},
},
hasFinalizer: true,
},
{
desc: "service with multiple finalizers",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{LoadBalancerCleanupFinalizer, "unrelated"},
},
},
hasFinalizer: true,
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
if hasFinalizer := HasLBFinalizer(tc.svc); hasFinalizer != tc.hasFinalizer {
t.Errorf("HasLBFinalizer() = %t, want %t", hasFinalizer, tc.hasFinalizer)
}
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment