aboutsummaryrefslogtreecommitdiffstats
path: root/src/kube2msb/kube2msb_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/kube2msb/kube2msb_test.go')
-rw-r--r--src/kube2msb/kube2msb_test.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/kube2msb/kube2msb_test.go b/src/kube2msb/kube2msb_test.go
index eea0f92..63efd8e 100644
--- a/src/kube2msb/kube2msb_test.go
+++ b/src/kube2msb/kube2msb_test.go
@@ -110,3 +110,98 @@ func TestSendPodWork(t *testing.T) {
}
}
}
+
+func TestRunBookKeeper(t *testing.T) {
+ kubeWorkQueue := make(chan KubeWork)
+ msbWorkQueue := make(chan MSBWork)
+
+ go runBookKeeper(kubeWorkQueue, msbWorkQueue)
+
+ serviceCases := []struct {
+ work KubeWork
+ ip string
+ msbAction MSBWorkAction
+ }{
+ {
+ KubeWork{
+ Action: KubeWorkAddService,
+ Service: createMockService("RunBookKeeper", "127.0.0.1", kapi.ServiceTypeClusterIP),
+ },
+ "127.0.0.1",
+ MSBWorkAddService,
+ },
+ {
+ KubeWork{
+ Action: KubeWorkUpdateService,
+ Service: createMockService("RunBookKeeper", "127.0.0.2", kapi.ServiceTypeNodePort),
+ },
+ "127.0.0.2",
+ MSBWorkAddService,
+ },
+ {
+ KubeWork{
+ Action: KubeWorkRemoveService,
+ Service: createMockService("RunBookKeeper", "127.0.0.3", kapi.ServiceTypeLoadBalancer),
+ },
+ "127.0.0.3",
+ MSBWorkRemoveService,
+ },
+ }
+
+ for _, c := range serviceCases {
+ // if c.work.Service.Spec.Type == kapi.ServiceTypeLoadBalancer {
+ // c.work.Service.Spec.LoadBalancerIP = "127.0.0.4"
+ // c.ip = "127.0.0.4"
+ // }
+ kubeWorkQueue <- c.work
+
+ if c.work.Action == KubeWorkUpdateService {
+ msbWorkValidate(t, msbWorkQueue, c.work.Service, MSBWorkRemoveService, c.ip)
+ msbWorkValidate(t, msbWorkQueue, c.work.Service, MSBWorkAddService, c.ip)
+ } else {
+ msbWorkValidate(t, msbWorkQueue, c.work.Service, c.msbAction, c.ip)
+ }
+ }
+
+ podCases := []struct {
+ work KubeWork
+ msbAction MSBWorkAction
+ ip string
+ }{
+ {
+ KubeWork{
+ Action: KubeWorkAddPod,
+ Pod: createMockPod("RunBookKeeper", "192.168.1.2"),
+ },
+ MSBWorkAddPod,
+ "192.168.1.2",
+ },
+ {
+ KubeWork{
+ Action: KubeWorkUpdatePod,
+ Pod: createMockPod("RunBookKeeper", "192.168.1.3"),
+ },
+ MSBWorkAddPod,
+ "",
+ },
+ {
+ KubeWork{
+ Action: KubeWorkRemovePod,
+ Pod: createMockPod("RunBookKeeper", "192.168.1.4"),
+ },
+ MSBWorkRemovePod,
+ "192.168.1.3",
+ },
+ }
+
+ for _, c := range podCases {
+ kubeWorkQueue <- c.work
+
+ if c.work.Action == KubeWorkUpdatePod {
+ msbWorkPodValidate(t, msbWorkQueue, c.work.Pod, MSBWorkRemovePod, "192.168.1.2")
+ msbWorkPodValidate(t, msbWorkQueue, c.work.Pod, MSBWorkAddPod, "192.168.1.3")
+ } else {
+ msbWorkPodValidate(t, msbWorkQueue, c.work.Pod, c.msbAction, c.ip)
+ }
+ }
+}