mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 03:25:35 +00:00
35 lines
722 B
Go
35 lines
722 B
Go
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||
|
|
||
|
package localapi
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"tailscale.com/client/tailscale/apitype"
|
||
|
)
|
||
|
|
||
|
func TestValidHost(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
host string
|
||
|
valid bool
|
||
|
}{
|
||
|
{"", true},
|
||
|
{apitype.LocalAPIHost, true},
|
||
|
{"localhost:9109", validLocalHost},
|
||
|
{"127.0.0.1:9110", validLocalHost},
|
||
|
{"[::1]:9111", validLocalHost},
|
||
|
{"100.100.100.100:41112", false},
|
||
|
{"10.0.0.1:41112", false},
|
||
|
{"37.16.9.210:41112", false},
|
||
|
}
|
||
|
|
||
|
for _, test := range tests {
|
||
|
t.Run(test.host, func(t *testing.T) {
|
||
|
if got := validHost(test.host); got != test.valid {
|
||
|
t.Errorf("validHost(%q)=%v, want %v", test.host, got, test.valid)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|