Skip to content

Commit 0f80651

Browse files
committed
Test utils.JoinHostPort()
1 parent b788876 commit 0f80651

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

utils/utils_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ func TestIsUnixAddr(t *testing.T) {
177177
}
178178
}
179179

180+
func TestJoinHostPort(t *testing.T) {
181+
subtests := []struct {
182+
name string
183+
host string
184+
port int
185+
output string
186+
}{
187+
{"empty", "", 0, ":0"},
188+
{"ipv4", "192.0.2.1", 80, "192.0.2.1:80"},
189+
{"ipv6", "2001:db8::", 443, "[2001:db8::]:443"},
190+
{"unix", "/tmp/sock", 5665, "/tmp/sock"},
191+
}
192+
193+
for _, st := range subtests {
194+
t.Run(st.name, func(t *testing.T) {
195+
require.Equal(t, st.output, JoinHostPort(st.host, st.port))
196+
})
197+
}
198+
}
199+
180200
func TestChanFromSlice(t *testing.T) {
181201
t.Run("Nil", func(t *testing.T) {
182202
ch := ChanFromSlice[int](nil)

0 commit comments

Comments
 (0)