add ut for MergeIP 63/34163/1
authorLvbo163 <lv.bo163@zte.com.cn>
Tue, 6 Mar 2018 01:10:51 +0000 (09:10 +0800)
committerLvbo163 <lv.bo163@zte.com.cn>
Tue, 6 Mar 2018 01:10:51 +0000 (09:10 +0800)
Issue-ID: MSB-177

Change-Id: I057566b6fb83d8d4c06c3e64be603d24cc9fe92f
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
src/kube2msb/msb_work_test.go [new file with mode: 0644]

diff --git a/src/kube2msb/msb_work_test.go b/src/kube2msb/msb_work_test.go
new file mode 100644 (file)
index 0000000..e271d22
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+Copyright 2018 ZTE, Inc. and others.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+package main
+
+import (
+       "testing"
+)
+
+func TestMergeIP(t *testing.T) {
+       cases := []struct{ ip, sInfo, want string }{
+               {"127.0.0.1", "{}", "{\"ip\":\"127.0.0.1\",}"},
+               {"127.0.0.1", "[{}]", "[{\"ip\":\"127.0.0.1\",}]"},
+               {"127.0.0.1", "{\"name\":\"msb\"}", "{\"ip\":\"127.0.0.1\",\"name\":\"msb\"}"},
+               {"127.0.0.1", "{\"name\":\"msb\", \"child\":{\"name\":\"childname\"}}",
+                       "{\"ip\":\"127.0.0.1\",\"name\":\"msb\", \"child\":{\"ip\":\"127.0.0.1\",\"name\":\"childname\"}}"},
+       }
+
+       for _, c := range cases {
+               got := mergeIP(c.ip, c.sInfo)
+               if got != c.want {
+                       t.Errorf("mergeIP(%ip, %sInfo) == %got, want %want", c.ip, c.sInfo, got, c.want)
+               }
+       }
+}