MCPcopy Create free account
hub / github.com/google/pprof / TestGetHostAndPort

Function TestGetHostAndPort

internal/driver/webui_test.go:257–290  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

255}
256
257func 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
292func TestIsLocalHost(t *testing.T) {
293 for _, s := range []string{"localhost:10000", "[::1]:10000", "127.0.0.1:10000"} {

Callers

nothing calls this directly

Calls 1

getHostAndPortFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…