(t *testing.T)
| 255 | } |
| 256 | |
| 257 | func TestGetHostAndPort(t *testing.T) { |
| 258 | if runtime.GOOS == "nacl" || runtime.GOOS == "js" { |
| 259 | t.Skip("test assumes tcp available") |
| 260 | } |
| 261 | |
| 262 | type testCase struct { |
| 263 | hostport string |
| 264 | wantHost string |
| 265 | wantPort int |
| 266 | wantRandomPort bool |
| 267 | } |
| 268 | |
| 269 | testCases := []testCase{ |
| 270 | {":", "localhost", 0, true}, |
| 271 | {":4681", "localhost", 4681, false}, |
| 272 | {"localhost:4681", "localhost", 4681, false}, |
| 273 | } |
| 274 | for _, tc := range testCases { |
| 275 | host, port, err := getHostAndPort(tc.hostport) |
| 276 | if err != nil { |
| 277 | t.Errorf("could not get host and port for %q: %v", tc.hostport, err) |
| 278 | } |
| 279 | if got, want := host, tc.wantHost; got != want { |
| 280 | t.Errorf("for %s, got host %s, want %s", tc.hostport, got, want) |
| 281 | continue |
| 282 | } |
| 283 | if !tc.wantRandomPort { |
| 284 | if got, want := port, tc.wantPort; got != want { |
| 285 | t.Errorf("for %s, got port %d, want %d", tc.hostport, got, want) |
| 286 | continue |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | func TestIsLocalHost(t *testing.T) { |
| 293 | for _, s := range []string{"localhost:10000", "[::1]:10000", "127.0.0.1:10000"} { |
nothing calls this directly
no test coverage detected
searching dependent graphs…