package utils import ( "github.com/stretchr/testify/assert" "testing" ) func assertSymbolicHost(t *testing.T, src string, host string, port uint16, path string, trailingSlash []string, ref bool) { a, b, c, ts, r, err := ParseSymbolicHost(src) assert.NoError(t, err) assert.Equal(t, host, a) assert.Equal(t, port, b) assert.Equal(t, path, c) assert.Equal(t, ts, trailingSlash) assert.Equal(t, ref, r) } func TestParseSymbolicHost(t *testing.T) { assertSymbolicHost(t, "*web:5600/hello", "*web", 5600, "/hello", nil, true) assertSymbolicHost(t, "*web:5600", "*web", 5600, "", nil, true) assertSymbolicHost(t, "*web/hello", "*web", 0, "/hello", nil, true) assertSymbolicHost(t, "*web", "*web", 0, "", nil, true) assertSymbolicHost(t, "*web:5600/hello~sec", "*web", 5600, "/hello", []string{"sec"}, true) assertSymbolicHost(t, "*web/hello~sec,host", "*web", 0, "/hello", []string{"sec", "host"}, true) assertSymbolicHost(t, "localhost:5600/hello", "localhost", 5600, "/hello", nil, false) assertSymbolicHost(t, "localhost:5600", "localhost", 5600, "", nil, false) assertSymbolicHost(t, "localhost/hello", "localhost", 0, "/hello", nil, false) assertSymbolicHost(t, "localhost", "localhost", 0, "", nil, false) assertSymbolicHost(t, "localhost:5600/hello~sec", "localhost", 5600, "/hello", []string{"sec"}, false) assertSymbolicHost(t, "localhost/hello~sec,host", "localhost", 0, "/hello", []string{"sec", "host"}, false) }