mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
cmd/tailscale: improve web server test structure
Signed-off-by: Dan Bond <danbond@protonmail.com>
This commit is contained in:
parent
4c684fcf8c
commit
52972679e6
@ -7,35 +7,37 @@
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestUrlOfListenAddr(t *testing.T) {
|
func TestUrlOfListenAddr(t *testing.T) {
|
||||||
t.Parallel()
|
tests := []struct {
|
||||||
|
name string
|
||||||
testTable := map[string]struct {
|
in, want string
|
||||||
addr string
|
|
||||||
expected string
|
|
||||||
}{
|
}{
|
||||||
"TestLocalhost": {
|
{
|
||||||
addr: "localhost:8088",
|
name: "TestLocalhost",
|
||||||
expected: "http://localhost:8088",
|
in: "localhost:8088",
|
||||||
|
want: "http://localhost:8088",
|
||||||
},
|
},
|
||||||
"TestNoHost": {
|
{
|
||||||
addr: ":8088",
|
name: "TestNoHost",
|
||||||
expected: "http://127.0.0.1:8088",
|
in: ":8088",
|
||||||
|
want: "http://127.0.0.1:8088",
|
||||||
},
|
},
|
||||||
"TestExplicitHost": {
|
{
|
||||||
addr: "127.0.0.2:8088",
|
name: "TestExplicitHost",
|
||||||
expected: "http://127.0.0.2:8088",
|
in: "127.0.0.2:8088",
|
||||||
|
want: "http://127.0.0.2:8088",
|
||||||
},
|
},
|
||||||
"TestIPv6": {
|
{
|
||||||
addr: "[::1]:8088",
|
name: "TestIPv6",
|
||||||
expected: "http://[::1]:8088",
|
in: "[::1]:8088",
|
||||||
|
want: "http://[::1]:8088",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, test := range testTable {
|
for _, tt := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
url := urlOfListenAddr(test.addr)
|
url := urlOfListenAddr(tt.in)
|
||||||
if url != test.expected {
|
if url != tt.want {
|
||||||
t.Errorf("expected url: '%s', got: '%s'", test.expected, url)
|
t.Errorf("expected url: %q, got: %q", tt.want, url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user