From 14d2440b87d85093e6440387aac3623387d315d0 Mon Sep 17 00:00:00 2001 From: zhangsheng02 Date: Fri, 17 Jul 2020 17:23:56 +0800 Subject: [PATCH 1/2] add GetAddressAndDialer unit test Signed-off-by: zhangsheng02 --- pkg/kubelet/util/util_unix_test.go | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/kubelet/util/util_unix_test.go b/pkg/kubelet/util/util_unix_test.go index fea4e409f5e..5ebeb2372e1 100644 --- a/pkg/kubelet/util/util_unix_test.go +++ b/pkg/kubelet/util/util_unix_test.go @@ -133,3 +133,41 @@ func TestIsUnixDomainSocket(t *testing.T) { assert.Equal(t, result, test.expectSocket, "Unexpected result from IsUnixDomainSocket: %v for %s", result, test.label) } } + +func TestGetAddressAndDialer(t *testing.T) { + tests := []struct { + endpoint string + expectError bool + expectedAddr string + }{ + { + endpoint: "unix:///tmp/s1.sock", + expectError: false, + expectedAddr: "/tmp/s1.sock", + }, + { + endpoint: "unix:///tmp/f6.sock", + expectError: false, + expectedAddr: "/tmp/f6.sock", + }, + { + endpoint: "tco:/localhost:9090", + expectError: true, + }, + { + // The misspelling is intentional to make it error + endpoint: "htta://free-test.com", + expectError: true, + }, + } + for _, test := range tests { + // just test addr and err + addr, _, err := GetAddressAndDialer(test.endpoint) + if test.expectError { + assert.NotNil(t, err, "expected error during parsing %s", test.endpoint) + continue + } + assert.Nil(t, err, "expected no error during parsing %s", test.endpoint) + assert.Equal(t, test.expectedAddr, addr) + } +} From dadc2ad385fe431b90a10a106f16a97eb1180c01 Mon Sep 17 00:00:00 2001 From: zhangsheng02 Date: Fri, 24 Jul 2020 09:32:34 +0800 Subject: [PATCH 2/2] add more testing cases Signed-off-by: zhangsheng02 --- pkg/kubelet/util/util_unix_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/util/util_unix_test.go b/pkg/kubelet/util/util_unix_test.go index 5ebeb2372e1..1234a0a0ad2 100644 --- a/pkg/kubelet/util/util_unix_test.go +++ b/pkg/kubelet/util/util_unix_test.go @@ -151,7 +151,7 @@ func TestGetAddressAndDialer(t *testing.T) { expectedAddr: "/tmp/f6.sock", }, { - endpoint: "tco:/localhost:9090", + endpoint: "tcp://localhost:9090", expectError: true, }, { @@ -159,6 +159,14 @@ func TestGetAddressAndDialer(t *testing.T) { endpoint: "htta://free-test.com", expectError: true, }, + { + endpoint: "https://www.youtube.com/", + expectError: true, + }, + { + endpoint: "http://www.baidu.com/", + expectError: true, + }, } for _, test := range tests { // just test addr and err