aboutsummaryrefslogtreecommitdiff
path: root/uri_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2017-01-09 10:50:56 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2017-01-09 10:50:56 +0200
commit0a7f0a797cd66b89588d0a7fdd670b706579a621 (patch)
tree13dbd645a0d77cdf3681b61d0de5a379be8d0a62 /uri_test.go
parentAdded RequestCtx.LocalIP() (diff)
downloadfasthttp-0a7f0a797cd66b89588d0a7fdd670b706579a621.tar.gz
fasthttp-0a7f0a797cd66b89588d0a7fdd670b706579a621.tar.bz2
fasthttp-0a7f0a797cd66b89588d0a7fdd670b706579a621.zip
Updated tests and documentation for URI.Parse and URI.Update* regarding uris without scheme
Diffstat (limited to 'uri_test.go')
-rw-r--r--uri_test.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/uri_test.go b/uri_test.go
index b86bb48..c10d21b 100644
--- a/uri_test.go
+++ b/uri_test.go
@@ -115,6 +115,7 @@ func TestURIUpdate(t *testing.T) {
// uri without scheme
testURIUpdate(t, "https://foo.bar/baz", "//aaa.bbb/cc?dd", "https://aaa.bbb/cc?dd")
+ testURIUpdate(t, "http://foo.bar/baz", "//aaa.bbb/cc?dd", "http://aaa.bbb/cc?dd")
}
func testURIUpdate(t *testing.T, base, update, result string) {
@@ -228,18 +229,25 @@ func testURIFullURI(t *testing.T, scheme, host, path, hash string, args *Args, e
}
func TestURIParseNilHost(t *testing.T) {
- testURIParseScheme(t, "http://google.com/foo?bar#baz", "http")
- testURIParseScheme(t, "HTtP://google.com/", "http")
- testURIParseScheme(t, "://google.com/", "http")
- testURIParseScheme(t, "fTP://aaa.com", "ftp")
- testURIParseScheme(t, "httPS://aaa.com", "https")
+ testURIParseScheme(t, "http://google.com/foo?bar#baz", "http", "google.com", "/foo?bar#baz")
+ testURIParseScheme(t, "HTtP://google.com/", "http", "google.com", "/")
+ testURIParseScheme(t, "://google.com/xyz", "http", "google.com", "/xyz")
+ testURIParseScheme(t, "//google.com/foobar", "http", "google.com", "/foobar")
+ testURIParseScheme(t, "fTP://aaa.com", "ftp", "aaa.com", "/")
+ testURIParseScheme(t, "httPS://aaa.com", "https", "aaa.com", "/")
}
-func testURIParseScheme(t *testing.T, uri, expectedScheme string) {
+func testURIParseScheme(t *testing.T, uri, expectedScheme, expectedHost, expectedRequestURI string) {
var u URI
u.Parse(nil, []byte(uri))
if string(u.Scheme()) != expectedScheme {
- t.Fatalf("Unexpected scheme %q. Expected %q for uri %q", u.Scheme(), expectedScheme, uri)
+ t.Fatalf("Unexpected scheme %q. Expecting %q for uri %q", u.Scheme(), expectedScheme, uri)
+ }
+ if string(u.Host()) != expectedHost {
+ t.Fatalf("Unexepcted host %q. Expecting %q for uri %q", u.Host(), expectedHost, uri)
+ }
+ if string(u.RequestURI()) != expectedRequestURI {
+ t.Fatalf("Unexepcted requestURI %q. Expecting %q for uri %q", u.RequestURI(), expectedRequestURI, uri)
}
}