Skip to content

Commit

Permalink
Add TestGetHost.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Oct 23, 2023
1 parent f41fc2f commit 5647565
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hlog/hlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,28 @@ func TestHostHandlerWithoutPort(t *testing.T) {
t.Errorf("Invalid log output, got: %s, want: %s", got, want)
}
}

func TestGetHost(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"", ""},
{"example.com:8080", "example.com"},
{"example.com", "example.com"},
{"invalid", "invalid"},
{"192.168.0.1:8080", "192.168.0.1"},
{"[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080", "2001:0db8:85a3:0000:0000:8a2e:0370:7334"},
{"こんにちは.com:8080", "こんにちは.com"},
}

for _, tt := range tests {
tt := tt
t.Run(tt.input, func(t *testing.T) {
result := getHost(tt.input)
if tt.expected != result {
t.Errorf("Invalid log output, got: %s, want: %s", result, tt.expected)
}
})
}
}

0 comments on commit 5647565

Please sign in to comment.