From 1d69f7c582ad1ddcb2040a293353e7fd96e3e946 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 5 Jul 2024 17:27:57 +0200 Subject: [PATCH] Test utils.JoinHostPort() --- utils/utils_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/utils/utils_test.go b/utils/utils_test.go index f3f9a899..725c909a 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -170,6 +170,26 @@ func TestIsUnixAddr(t *testing.T) { } } +func TestJoinHostPort(t *testing.T) { + subtests := []struct { + name string + host string + port int + output string + }{ + {"empty", "", 0, ":0"}, + {"ipv4", "192.0.2.1", 80, "192.0.2.1:80"}, + {"ipv6", "2001:db8::", 443, "[2001:db8::]:443"}, + {"unix", "/tmp/sock", 5665, "/tmp/sock"}, + } + + for _, st := range subtests { + t.Run(st.name, func(t *testing.T) { + require.Equal(t, st.output, JoinHostPort(st.host, st.port)) + }) + } +} + func TestChanFromSlice(t *testing.T) { t.Run("Nil", func(t *testing.T) { ch := ChanFromSlice[int](nil)