aboutsummaryrefslogtreecommitdiff
path: root/uri_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-15 23:47:22 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-15 23:47:22 +0200
commitf1f78f0828ead1f1e97d7506d1cda3d21077632a (patch)
tree329bd48407f9cca99c7c7283806e8ef5992751cf /uri_test.go
parentAdded DoTimeout() to client (diff)
downloadfasthttp-f1f78f0828ead1f1e97d7506d1cda3d21077632a.tar.gz
fasthttp-f1f78f0828ead1f1e97d7506d1cda3d21077632a.tar.bz2
fasthttp-f1f78f0828ead1f1e97d7506d1cda3d21077632a.zip
Hide Request.URI and Request.PostArgs behind accessors, which automatically call parse URI and PostArgs on first access
Diffstat (limited to 'uri_test.go')
-rw-r--r--uri_test.go39
1 files changed, 17 insertions, 22 deletions
diff --git a/uri_test.go b/uri_test.go
index 3dc5417..173a02b 100644
--- a/uri_test.go
+++ b/uri_test.go
@@ -54,37 +54,37 @@ func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string)
}
}
-func TestURIAppendBytes(t *testing.T) {
+func TestURIFullURI(t *testing.T) {
var args Args
// empty scheme, path and hash
- testURIAppendBytes(t, "", "foobar.com", "", "", &args, "http://foobar.com/")
+ testURIFullURI(t, "", "foobar.com", "", "", &args, "http://foobar.com/")
// empty scheme and hash
- testURIAppendBytes(t, "", "aa.com", "/foo/bar", "", &args, "http://aa.com/foo/bar")
+ testURIFullURI(t, "", "aa.com", "/foo/bar", "", &args, "http://aa.com/foo/bar")
// empty hash
- testURIAppendBytes(t, "fTP", "XXx.com", "/foo", "", &args, "ftp://xxx.com/foo")
+ testURIFullURI(t, "fTP", "XXx.com", "/foo", "", &args, "ftp://xxx.com/foo")
// empty args
- testURIAppendBytes(t, "https", "xx.com", "/", "aaa", &args, "https://xx.com/#aaa")
+ testURIFullURI(t, "https", "xx.com", "/", "aaa", &args, "https://xx.com/#aaa")
// non-empty args and non-ASCII path
args.Set("foo", "bar")
args.Set("xxx", "йух")
- testURIAppendBytes(t, "", "xxx.com", "/тест123", "2er", &args, "http://xxx.com/%D1%82%D0%B5%D1%81%D1%82123?foo=bar&xxx=%D0%B9%D1%83%D1%85#2er")
+ testURIFullURI(t, "", "xxx.com", "/тест123", "2er", &args, "http://xxx.com/%D1%82%D0%B5%D1%81%D1%82123?foo=bar&xxx=%D0%B9%D1%83%D1%85#2er")
// test with empty args and non-empty query string
var u URI
u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq"))
- buf := u.AppendBytes(nil)
+ uri := u.FullURI()
expectedURI := "http://google.com/foo?bar=baz&baraz#qqqq"
- if string(buf) != expectedURI {
- t.Fatalf("Unexpected URI: %q. Expected %q", buf, expectedURI)
+ if string(uri) != expectedURI {
+ t.Fatalf("Unexpected URI: %q. Expected %q", uri, expectedURI)
}
}
-func testURIAppendBytes(t *testing.T, scheme, host, path, hash string, args *Args, expectedURI string) {
+func testURIFullURI(t *testing.T, scheme, host, path, hash string, args *Args, expectedURI string) {
var u URI
u.Scheme = []byte(scheme)
@@ -93,14 +93,9 @@ func testURIAppendBytes(t *testing.T, scheme, host, path, hash string, args *Arg
u.Hash = []byte(hash)
u.QueryArgs = *args
- prefix := []byte("prefix")
- buf := prefix
- buf = u.AppendBytes(buf)
- if !bytes.Equal(prefix, buf[:len(prefix)]) {
- t.Fatalf("Unepxected prefix %q. Expected %q", buf[:len(prefix)], prefix)
- }
- if string(buf[len(prefix):]) != expectedURI {
- t.Fatalf("Unexpected URI: %q. Expected %q", buf[len(prefix):], expectedURI)
+ uri := u.FullURI()
+ if string(uri) != expectedURI {
+ t.Fatalf("Unexpected URI: %q. Expected %q", uri, expectedURI)
}
}
@@ -125,7 +120,7 @@ func TestURIParse(t *testing.T) {
// no args
testURIParse(t, &u, "aaa", "sdfdsf",
- "http://aaa/sdfdsf", "aaa", "sdfdsf", "sdfdsf", "", "")
+ "http://aaa/sdfdsf", "aaa", "/sdfdsf", "sdfdsf", "", "")
// args
testURIParse(t, &u, "xx", "/aa?ss",
@@ -137,7 +132,7 @@ func TestURIParse(t *testing.T) {
// encoded path
testURIParse(t, &u, "aa.com", "/Test%20+%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf",
- "http://aa.com/Test%20+%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf", "aa.com", "/Test + при", "/Test%20+%20%D0%BF%D1%80%D0%B8", "asdf=%20%20&s=12", "sdf")
+ "http://aa.com/Test%20%2B%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf", "aa.com", "/Test + при", "/Test%20+%20%D0%BF%D1%80%D0%B8", "asdf=%20%20&s=12", "sdf")
// host in uppercase
testURIParse(t, &u, "FOObar.COM", "/bC?De=F#Gh",
@@ -166,8 +161,8 @@ func testURIParse(t *testing.T, u *URI, host, uri,
expectedURI, expectedHost, expectedPath, expectedPathOriginal, expectedArgs, expectedHash string) {
u.Parse([]byte(host), []byte(uri))
- if !bytes.Equal(u.URI, []byte(expectedURI)) {
- t.Fatalf("Unexpected uri %q. Expected %q. host=%q, uri=%q", u.URI, expectedURI, host, uri)
+ if !bytes.Equal(u.FullURI(), []byte(expectedURI)) {
+ t.Fatalf("Unexpected uri %q. Expected %q. host=%q, uri=%q", u.FullURI(), expectedURI, host, uri)
}
if !bytes.Equal(u.Host, []byte(expectedHost)) {
t.Fatalf("Unexpected host %q. Expected %q. host=%q, uri=%q", u.Host, expectedHost, host, uri)