func getServerURL() string { hostport, err := netutil.HostWithPort(server) if err != nil { os.Exit(1) } serverURL := &url.URL{ Scheme: "http", Host: hostport, } return serverURL.String() }
func TestHostWithPort(t *testing.T) { tests := []struct { input string hostport string expectedErr bool }{ {":8080", ":8080", false}, {"localhost:8080", "localhost:8080", false}, {"_xmpp-server._tcp.google.com", "_xmpp-server._tcp.google.com:5269", false}, {"localhost", "", true}, {"[localhost", "", true}, } for _, tt := range tests { hostport, err := netutil.HostWithPort(tt.input) if tt.expectedErr { assert.Error(t, err, tt.input) } assert.Equal(t, tt.hostport, hostport, tt.input) } }