aboutsummaryrefslogtreecommitdiff
path: root/cookie_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-19 13:03:35 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-19 13:03:35 +0200
commit6489c32a901f198a69333eaa3cf883ad40daf6f0 (patch)
treee0f5599fcb25b3e4af40bc3b823391a277c4d5f9 /cookie_test.go
parentAdded AcquireArgs and ReleaseArgs helper functions (diff)
downloadfasthttp-6489c32a901f198a69333eaa3cf883ad40daf6f0.tar.gz
fasthttp-6489c32a901f198a69333eaa3cf883ad40daf6f0.tar.bz2
fasthttp-6489c32a901f198a69333eaa3cf883ad40daf6f0.zip
Added AcquireCookie / ReleaseCookie helpers
Diffstat (limited to 'cookie_test.go')
-rw-r--r--cookie_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/cookie_test.go b/cookie_test.go
index f1565e6..dcddf79 100644
--- a/cookie_test.go
+++ b/cookie_test.go
@@ -3,8 +3,67 @@ package fasthttp
import (
"strings"
"testing"
+ "time"
)
+func TestCookieAcquireReleaseSequential(t *testing.T) {
+ testCookieAcquireRelease(t)
+}
+
+func TestCookieAcquireReleaseConcurrent(t *testing.T) {
+ ch := make(chan struct{}, 10)
+ for i := 0; i < 10; i++ {
+ go func() {
+ testCookieAcquireRelease(t)
+ ch <- struct{}{}
+ }()
+ }
+ for i := 0; i < 10; i++ {
+ select {
+ case <-ch:
+ case <-time.After(time.Second):
+ t.Fatalf("timeout")
+ }
+ }
+}
+
+func testCookieAcquireRelease(t *testing.T) {
+ c := AcquireCookie()
+
+ key := "foo"
+ c.SetKey(key)
+
+ value := "bar"
+ c.SetValue(value)
+
+ domain := "foo.bar.com"
+ c.SetDomain(domain)
+
+ path := "/foi/bar/aaa"
+ c.SetPath(path)
+
+ s := c.String()
+ c.Reset()
+ if err := c.Parse(s); err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
+
+ if string(c.Key()) != key {
+ t.Fatalf("unexpected cookie name %q. Expecting %q", c.Key(), key)
+ }
+ if string(c.Value()) != value {
+ t.Fatalf("unexpected cookie value %q. Expecting %q", c.Value(), value)
+ }
+ if string(c.Domain()) != domain {
+ t.Fatalf("unexpected domain %q. Expecting %q", c.Domain(), domain)
+ }
+ if string(c.Path()) != path {
+ t.Fatalf("unexpected path %q. Expecting %q", c.Path(), path)
+ }
+
+ ReleaseCookie(c)
+}
+
func TestCookieParse(t *testing.T) {
testCookieParse(t, "foo", "foo")
testCookieParse(t, "foo=bar", "foo=bar")