From 817d8346892314a97ab0110df83cf0b066c85e17 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Tue, 6 Mar 2018 09:10:51 +0800 Subject: add ut for MergeIP Issue-ID: MSB-177 Change-Id: I057566b6fb83d8d4c06c3e64be603d24cc9fe92f Signed-off-by: Lvbo163 --- src/kube2msb/msb_work_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/kube2msb/msb_work_test.go (limited to 'src') diff --git a/src/kube2msb/msb_work_test.go b/src/kube2msb/msb_work_test.go new file mode 100644 index 0000000..e271d22 --- /dev/null +++ b/src/kube2msb/msb_work_test.go @@ -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) + } + } +} -- cgit 1.2.3-korg