summaryrefslogtreecommitdiff
path: root/edgemesh
diff options
context:
space:
mode:
authorTianTianBigWang <zilong.wang@daocloud.io>2021-03-21 10:58:33 +0800
committerTianTianBigWang <zilong.wang@daocloud.io>2021-03-21 19:27:50 +0800
commit5c9c20def413d626e1f430f91a101b680a8f5f9a (patch)
treedf366a5d5fc2667ba861252054fb34d15bb1b124 /edgemesh
parentMerge pull request #2668 from fisherxu/v161-changelog (diff)
downloadkubeedge-5c9c20def413d626e1f430f91a101b680a8f5f9a.tar.gz
add unit test for edgemesh common utils.go
Signed-off-by: TianTianBigWang <zilong.wang@daocloud.io>
Diffstat (limited to 'edgemesh')
-rw-r--r--edgemesh/pkg/common/utils_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/edgemesh/pkg/common/utils_test.go b/edgemesh/pkg/common/utils_test.go
new file mode 100644
index 000000000..d09e650cc
--- /dev/null
+++ b/edgemesh/pkg/common/utils_test.go
@@ -0,0 +1,83 @@
+package common
+
+import (
+ "net"
+ "reflect"
+ "testing"
+
+ "github.com/go-chassis/go-chassis/core/common"
+)
+
+func TestGetInterfaceIP(t *testing.T) {
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ args args
+ want net.IP
+ wantErr bool
+ }{
+ {
+ name: "TestGetInterfaceIP(): Case 1: Interface found",
+ args: args{name: "lo0"},
+ want: net.ParseIP("127.0.0.1"),
+ wantErr: false,
+ },
+ {
+ name: "TestGetInterfaceIP(): Case 2: Interface not found",
+ args: args{name: "notfound"},
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := GetInterfaceIP(tt.args.name)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("GetInterfaceIP() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("GetInterfaceIP() got = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSplitServiceKey(t *testing.T) {
+ type args struct {
+ key string
+ }
+ tests := []struct {
+ name string
+ args args
+ wantName string
+ wantNamespace string
+ }{
+ {
+ name: "TestSplitServiceKey(): Case 1: Test with name and namespace",
+ args: args{key: "key.test"},
+ wantName: "key",
+ wantNamespace: "test",
+ },
+ {
+ name: "TestSplitServiceKey(): Case 2: Test with name",
+ args: args{key: "key"},
+ wantName: "key",
+ wantNamespace: common.DefaultValue,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotName, gotNamespace := SplitServiceKey(tt.args.key)
+ if gotName != tt.wantName {
+ t.Errorf("SplitServiceKey() gotName = %v, want %v", gotName, tt.wantName)
+ return
+ }
+ if gotNamespace != tt.wantNamespace {
+ t.Errorf("SplitServiceKey() gotNamespace = %v, want %v", gotNamespace, tt.wantNamespace)
+ }
+ })
+ }
+}