aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/kube2msb/kube_work_test.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/kube2msb/kube_work_test.go b/src/kube2msb/kube_work_test.go
index f67608a..43ae17e 100644
--- a/src/kube2msb/kube_work_test.go
+++ b/src/kube2msb/kube_work_test.go
@@ -219,7 +219,6 @@ func TestAddPodKube(t *testing.T) {
}
-
func TestRemovePodKube(t *testing.T) {
client := newClientBookKeeper()
msbWorkQueue := make(chan MSBWork, 10)
@@ -246,4 +245,43 @@ func TestRemovePodKube(t *testing.T) {
if _, ok := client.pods[pod.Name]; ok {
t.Errorf("remove pod error, pod still exists in client.pods")
}
-} \ No newline at end of file
+}
+
+func TestUpdatePodKube(t *testing.T) {
+ client := newClientBookKeeper()
+ msbWorkQueue := make(chan MSBWork, 10)
+ client.msbQueue = msbWorkQueue
+
+ // exception process
+ // TODO ServiceKey not set , cannot check result for there would be no return
+ podWithoutServiceKey := kapi.Pod{}
+ client.UpdatePod(&podWithoutServiceKey)
+
+ // normal process
+ // update exist Pod
+ existPod := createMockPod("mockPod", "192.168.10.11")
+ client.AddPod(existPod)
+ msbWorkPodValidate(t, msbWorkQueue, existPod, MSBWorkAddPod)
+ if _, ok := client.pods[existPod.Name]; !ok {
+ t.Errorf("add pod error, pod not exists in client.pods")
+ }
+ // update service info
+ existPod.Status.PodIP = "0.0.0.0"
+ client.UpdatePod(existPod)
+ msbWorkPodValidate(t, msbWorkQueue, existPod, MSBWorkRemovePod)
+ msbWorkPodValidate(t, msbWorkQueue, existPod, MSBWorkAddPod)
+ if updatedExistPod, ok := client.pods[existPod.Name]; !ok || updatedExistPod.Status.PodIP != existPod.Status.PodIP {
+ t.Errorf("add pod error, pod not exists in client.pods")
+ }
+
+ // update not exist service
+ notExistPod := createMockPod("mockNotExistPod", "192.168.10.11")
+ if _, ok := client.pods[notExistPod.Name]; ok {
+ t.Errorf("mockNotExistPod should not exist before it has been added")
+ }
+ client.UpdatePod(notExistPod)
+ msbWorkPodValidate(t, msbWorkQueue, notExistPod, MSBWorkAddPod)
+ if _, ok := client.pods[notExistPod.Name]; !ok {
+ t.Errorf("mockNotExistPod should not exist before it has been added")
+ }
+}