summaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/gorilla
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-02-23 14:07:01 -0500
committerChristopher Speller <crspeller@gmail.com>2016-02-23 14:07:01 -0500
commit962b18411893e1fffd10c2b6370ac34aba62f146 (patch)
tree0dfdd3735c18e2c242957cc79d6ca48bce8de1f5 /Godeps/_workspace/src/github.com/gorilla
parent11093ddb51a70622287aac20108be6c6aa2eb76d (diff)
downloadchat-962b18411893e1fffd10c2b6370ac34aba62f146.tar.gz
chat-962b18411893e1fffd10c2b6370ac34aba62f146.tar.bz2
chat-962b18411893e1fffd10c2b6370ac34aba62f146.zip
Updating golang dependancies (godep)
Diffstat (limited to 'Godeps/_workspace/src/github.com/gorilla')
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/context/context_test.go161
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/mux/bench_test.go21
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go1334
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/mux/old_test.go714
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/bench_test.go19
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go410
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go72
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/conn_test.go272
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go119
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/server_test.go33
-rw-r--r--Godeps/_workspace/src/github.com/gorilla/websocket/util_test.go34
11 files changed, 0 insertions, 3189 deletions
diff --git a/Godeps/_workspace/src/github.com/gorilla/context/context_test.go b/Godeps/_workspace/src/github.com/gorilla/context/context_test.go
deleted file mode 100644
index 9814c501e..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/context/context_test.go
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context
-
-import (
- "net/http"
- "testing"
-)
-
-type keyType int
-
-const (
- key1 keyType = iota
- key2
-)
-
-func TestContext(t *testing.T) {
- assertEqual := func(val interface{}, exp interface{}) {
- if val != exp {
- t.Errorf("Expected %v, got %v.", exp, val)
- }
- }
-
- r, _ := http.NewRequest("GET", "http://localhost:8080/", nil)
- emptyR, _ := http.NewRequest("GET", "http://localhost:8080/", nil)
-
- // Get()
- assertEqual(Get(r, key1), nil)
-
- // Set()
- Set(r, key1, "1")
- assertEqual(Get(r, key1), "1")
- assertEqual(len(data[r]), 1)
-
- Set(r, key2, "2")
- assertEqual(Get(r, key2), "2")
- assertEqual(len(data[r]), 2)
-
- //GetOk
- value, ok := GetOk(r, key1)
- assertEqual(value, "1")
- assertEqual(ok, true)
-
- value, ok = GetOk(r, "not exists")
- assertEqual(value, nil)
- assertEqual(ok, false)
-
- Set(r, "nil value", nil)
- value, ok = GetOk(r, "nil value")
- assertEqual(value, nil)
- assertEqual(ok, true)
-
- // GetAll()
- values := GetAll(r)
- assertEqual(len(values), 3)
-
- // GetAll() for empty request
- values = GetAll(emptyR)
- if values != nil {
- t.Error("GetAll didn't return nil value for invalid request")
- }
-
- // GetAllOk()
- values, ok = GetAllOk(r)
- assertEqual(len(values), 3)
- assertEqual(ok, true)
-
- // GetAllOk() for empty request
- values, ok = GetAllOk(emptyR)
- assertEqual(value, nil)
- assertEqual(ok, false)
-
- // Delete()
- Delete(r, key1)
- assertEqual(Get(r, key1), nil)
- assertEqual(len(data[r]), 2)
-
- Delete(r, key2)
- assertEqual(Get(r, key2), nil)
- assertEqual(len(data[r]), 1)
-
- // Clear()
- Clear(r)
- assertEqual(len(data), 0)
-}
-
-func parallelReader(r *http.Request, key string, iterations int, wait, done chan struct{}) {
- <-wait
- for i := 0; i < iterations; i++ {
- Get(r, key)
- }
- done <- struct{}{}
-
-}
-
-func parallelWriter(r *http.Request, key, value string, iterations int, wait, done chan struct{}) {
- <-wait
- for i := 0; i < iterations; i++ {
- Set(r, key, value)
- }
- done <- struct{}{}
-
-}
-
-func benchmarkMutex(b *testing.B, numReaders, numWriters, iterations int) {
-
- b.StopTimer()
- r, _ := http.NewRequest("GET", "http://localhost:8080/", nil)
- done := make(chan struct{})
- b.StartTimer()
-
- for i := 0; i < b.N; i++ {
- wait := make(chan struct{})
-
- for i := 0; i < numReaders; i++ {
- go parallelReader(r, "test", iterations, wait, done)
- }
-
- for i := 0; i < numWriters; i++ {
- go parallelWriter(r, "test", "123", iterations, wait, done)
- }
-
- close(wait)
-
- for i := 0; i < numReaders+numWriters; i++ {
- <-done
- }
-
- }
-
-}
-
-func BenchmarkMutexSameReadWrite1(b *testing.B) {
- benchmarkMutex(b, 1, 1, 32)
-}
-func BenchmarkMutexSameReadWrite2(b *testing.B) {
- benchmarkMutex(b, 2, 2, 32)
-}
-func BenchmarkMutexSameReadWrite4(b *testing.B) {
- benchmarkMutex(b, 4, 4, 32)
-}
-func BenchmarkMutex1(b *testing.B) {
- benchmarkMutex(b, 2, 8, 32)
-}
-func BenchmarkMutex2(b *testing.B) {
- benchmarkMutex(b, 16, 4, 64)
-}
-func BenchmarkMutex3(b *testing.B) {
- benchmarkMutex(b, 1, 2, 128)
-}
-func BenchmarkMutex4(b *testing.B) {
- benchmarkMutex(b, 128, 32, 256)
-}
-func BenchmarkMutex5(b *testing.B) {
- benchmarkMutex(b, 1024, 2048, 64)
-}
-func BenchmarkMutex6(b *testing.B) {
- benchmarkMutex(b, 2048, 1024, 512)
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/bench_test.go b/Godeps/_workspace/src/github.com/gorilla/mux/bench_test.go
deleted file mode 100644
index c5f97b2b2..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/mux/bench_test.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mux
-
-import (
- "net/http"
- "testing"
-)
-
-func BenchmarkMux(b *testing.B) {
- router := new(Router)
- handler := func(w http.ResponseWriter, r *http.Request) {}
- router.HandleFunc("/v1/{v1}", handler)
-
- request, _ := http.NewRequest("GET", "/v1/anything", nil)
- for i := 0; i < b.N; i++ {
- router.ServeHTTP(nil, request)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go b/Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go
deleted file mode 100644
index d1eae9265..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go
+++ /dev/null
@@ -1,1334 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mux
-
-import (
- "fmt"
- "net/http"
- "strings"
- "testing"
-
- "github.com/gorilla/context"
-)
-
-func (r *Route) GoString() string {
- matchers := make([]string, len(r.matchers))
- for i, m := range r.matchers {
- matchers[i] = fmt.Sprintf("%#v", m)
- }
- return fmt.Sprintf("&Route{matchers:[]matcher{%s}}", strings.Join(matchers, ", "))
-}
-
-func (r *routeRegexp) GoString() string {
- return fmt.Sprintf("&routeRegexp{template: %q, matchHost: %t, matchQuery: %t, strictSlash: %t, regexp: regexp.MustCompile(%q), reverse: %q, varsN: %v, varsR: %v", r.template, r.matchHost, r.matchQuery, r.strictSlash, r.regexp.String(), r.reverse, r.varsN, r.varsR)
-}
-
-type routeTest struct {
- title string // title of the test
- route *Route // the route being tested
- request *http.Request // a request to test the route
- vars map[string]string // the expected vars of the match
- host string // the expected host of the match
- path string // the expected path of the match
- shouldMatch bool // whether the request is expected to match the route at all
- shouldRedirect bool // whether the request should result in a redirect
-}
-
-func TestHost(t *testing.T) {
- // newRequestHost a new request with a method, url, and host header
- newRequestHost := func(method, url, host string) *http.Request {
- req, err := http.NewRequest(method, url, nil)
- if err != nil {
- panic(err)
- }
- req.Host = host
- return req
- }
-
- tests := []routeTest{
- {
- title: "Host route match",
- route: new(Route).Host("aaa.bbb.ccc"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route, wrong host in request URL",
- route: new(Route).Host("aaa.bbb.ccc"),
- request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Host route with port, match",
- route: new(Route).Host("aaa.bbb.ccc:1234"),
- request: newRequest("GET", "http://aaa.bbb.ccc:1234/111/222/333"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc:1234",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route with port, wrong port in request URL",
- route: new(Route).Host("aaa.bbb.ccc:1234"),
- request: newRequest("GET", "http://aaa.bbb.ccc:9999/111/222/333"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc:1234",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Host route, match with host in request header",
- route: new(Route).Host("aaa.bbb.ccc"),
- request: newRequestHost("GET", "/111/222/333", "aaa.bbb.ccc"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route, wrong host in request header",
- route: new(Route).Host("aaa.bbb.ccc"),
- request: newRequestHost("GET", "/111/222/333", "aaa.222.ccc"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: false,
- },
- // BUG {new(Route).Host("aaa.bbb.ccc:1234"), newRequestHost("GET", "/111/222/333", "aaa.bbb.ccc:1234"), map[string]string{}, "aaa.bbb.ccc:1234", "", true},
- {
- title: "Host route with port, wrong host in request header",
- route: new(Route).Host("aaa.bbb.ccc:1234"),
- request: newRequestHost("GET", "/111/222/333", "aaa.bbb.ccc:9999"),
- vars: map[string]string{},
- host: "aaa.bbb.ccc:1234",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Host route with pattern, match",
- route: new(Route).Host("aaa.{v1:[a-z]{3}}.ccc"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v1": "bbb"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route with pattern, additional capturing group, match",
- route: new(Route).Host("aaa.{v1:[a-z]{2}(b|c)}.ccc"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v1": "bbb"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route with pattern, wrong host in request URL",
- route: new(Route).Host("aaa.{v1:[a-z]{3}}.ccc"),
- request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
- vars: map[string]string{"v1": "bbb"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Host route with multiple patterns, match",
- route: new(Route).Host("{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route with multiple patterns, wrong host in request URL",
- route: new(Route).Host("{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}"),
- request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
- vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Host route with hyphenated name and pattern, match",
- route: new(Route).Host("aaa.{v-1:[a-z]{3}}.ccc"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v-1": "bbb"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route with hyphenated name and pattern, additional capturing group, match",
- route: new(Route).Host("aaa.{v-1:[a-z]{2}(b|c)}.ccc"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v-1": "bbb"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host route with multiple hyphenated names and patterns, match",
- route: new(Route).Host("{v-1:[a-z]{3}}.{v-2:[a-z]{3}}.{v-3:[a-z]{3}}"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v-1": "aaa", "v-2": "bbb", "v-3": "ccc"},
- host: "aaa.bbb.ccc",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Path route with single pattern with pipe, match",
- route: new(Route).Path("/{category:a|b/c}"),
- request: newRequest("GET", "http://localhost/a"),
- vars: map[string]string{"category": "a"},
- host: "",
- path: "/a",
- shouldMatch: true,
- },
- {
- title: "Path route with single pattern with pipe, match",
- route: new(Route).Path("/{category:a|b/c}"),
- request: newRequest("GET", "http://localhost/b/c"),
- vars: map[string]string{"category": "b/c"},
- host: "",
- path: "/b/c",
- shouldMatch: true,
- },
- {
- title: "Path route with multiple patterns with pipe, match",
- route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"),
- request: newRequest("GET", "http://localhost/a/product_name/1"),
- vars: map[string]string{"category": "a", "product": "product_name", "id": "1"},
- host: "",
- path: "/a/product_name/1",
- shouldMatch: true,
- },
- {
- title: "Path route with multiple patterns with pipe, match",
- route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"),
- request: newRequest("GET", "http://localhost/b/c/product_name/1"),
- vars: map[string]string{"category": "b/c", "product": "product_name", "id": "1"},
- host: "",
- path: "/b/c/product_name/1",
- shouldMatch: true,
- },
- }
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestPath(t *testing.T) {
- tests := []routeTest{
- {
- title: "Path route, match",
- route: new(Route).Path("/111/222/333"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{},
- host: "",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Path route, match with trailing slash in request and path",
- route: new(Route).Path("/111/"),
- request: newRequest("GET", "http://localhost/111/"),
- vars: map[string]string{},
- host: "",
- path: "/111/",
- shouldMatch: true,
- },
- {
- title: "Path route, do not match with trailing slash in path",
- route: new(Route).Path("/111/"),
- request: newRequest("GET", "http://localhost/111"),
- vars: map[string]string{},
- host: "",
- path: "/111",
- shouldMatch: false,
- },
- {
- title: "Path route, do not match with trailing slash in request",
- route: new(Route).Path("/111"),
- request: newRequest("GET", "http://localhost/111/"),
- vars: map[string]string{},
- host: "",
- path: "/111/",
- shouldMatch: false,
- },
- {
- title: "Path route, wrong path in request in request URL",
- route: new(Route).Path("/111/222/333"),
- request: newRequest("GET", "http://localhost/1/2/3"),
- vars: map[string]string{},
- host: "",
- path: "/111/222/333",
- shouldMatch: false,
- },
- {
- title: "Path route with pattern, match",
- route: new(Route).Path("/111/{v1:[0-9]{3}}/333"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{"v1": "222"},
- host: "",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Path route with pattern, URL in request does not match",
- route: new(Route).Path("/111/{v1:[0-9]{3}}/333"),
- request: newRequest("GET", "http://localhost/111/aaa/333"),
- vars: map[string]string{"v1": "222"},
- host: "",
- path: "/111/222/333",
- shouldMatch: false,
- },
- {
- title: "Path route with multiple patterns, match",
- route: new(Route).Path("/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{"v1": "111", "v2": "222", "v3": "333"},
- host: "",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Path route with multiple patterns, URL in request does not match",
- route: new(Route).Path("/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/aaa/333"),
- vars: map[string]string{"v1": "111", "v2": "222", "v3": "333"},
- host: "",
- path: "/111/222/333",
- shouldMatch: false,
- },
- {
- title: "Path route with multiple patterns with pipe, match",
- route: new(Route).Path("/{category:a|(b/c)}/{product}/{id:[0-9]+}"),
- request: newRequest("GET", "http://localhost/a/product_name/1"),
- vars: map[string]string{"category": "a", "product": "product_name", "id": "1"},
- host: "",
- path: "/a/product_name/1",
- shouldMatch: true,
- },
- {
- title: "Path route with hyphenated name and pattern, match",
- route: new(Route).Path("/111/{v-1:[0-9]{3}}/333"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{"v-1": "222"},
- host: "",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Path route with multiple hyphenated names and patterns, match",
- route: new(Route).Path("/{v-1:[0-9]{3}}/{v-2:[0-9]{3}}/{v-3:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{"v-1": "111", "v-2": "222", "v-3": "333"},
- host: "",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Path route with multiple hyphenated names and patterns with pipe, match",
- route: new(Route).Path("/{product-category:a|(b/c)}/{product-name}/{product-id:[0-9]+}"),
- request: newRequest("GET", "http://localhost/a/product_name/1"),
- vars: map[string]string{"product-category": "a", "product-name": "product_name", "product-id": "1"},
- host: "",
- path: "/a/product_name/1",
- shouldMatch: true,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestPathPrefix(t *testing.T) {
- tests := []routeTest{
- {
- title: "PathPrefix route, match",
- route: new(Route).PathPrefix("/111"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{},
- host: "",
- path: "/111",
- shouldMatch: true,
- },
- {
- title: "PathPrefix route, match substring",
- route: new(Route).PathPrefix("/1"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{},
- host: "",
- path: "/1",
- shouldMatch: true,
- },
- {
- title: "PathPrefix route, URL prefix in request does not match",
- route: new(Route).PathPrefix("/111"),
- request: newRequest("GET", "http://localhost/1/2/3"),
- vars: map[string]string{},
- host: "",
- path: "/111",
- shouldMatch: false,
- },
- {
- title: "PathPrefix route with pattern, match",
- route: new(Route).PathPrefix("/111/{v1:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{"v1": "222"},
- host: "",
- path: "/111/222",
- shouldMatch: true,
- },
- {
- title: "PathPrefix route with pattern, URL prefix in request does not match",
- route: new(Route).PathPrefix("/111/{v1:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/aaa/333"),
- vars: map[string]string{"v1": "222"},
- host: "",
- path: "/111/222",
- shouldMatch: false,
- },
- {
- title: "PathPrefix route with multiple patterns, match",
- route: new(Route).PathPrefix("/{v1:[0-9]{3}}/{v2:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/222/333"),
- vars: map[string]string{"v1": "111", "v2": "222"},
- host: "",
- path: "/111/222",
- shouldMatch: true,
- },
- {
- title: "PathPrefix route with multiple patterns, URL prefix in request does not match",
- route: new(Route).PathPrefix("/{v1:[0-9]{3}}/{v2:[0-9]{3}}"),
- request: newRequest("GET", "http://localhost/111/aaa/333"),
- vars: map[string]string{"v1": "111", "v2": "222"},
- host: "",
- path: "/111/222",
- shouldMatch: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestHostPath(t *testing.T) {
- tests := []routeTest{
- {
- title: "Host and Path route, match",
- route: new(Route).Host("aaa.bbb.ccc").Path("/111/222/333"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Host and Path route, wrong host in request URL",
- route: new(Route).Host("aaa.bbb.ccc").Path("/111/222/333"),
- request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Host and Path route with pattern, match",
- route: new(Route).Host("aaa.{v1:[a-z]{3}}.ccc").Path("/111/{v2:[0-9]{3}}/333"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v1": "bbb", "v2": "222"},
- host: "aaa.bbb.ccc",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Host and Path route with pattern, URL in request does not match",
- route: new(Route).Host("aaa.{v1:[a-z]{3}}.ccc").Path("/111/{v2:[0-9]{3}}/333"),
- request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
- vars: map[string]string{"v1": "bbb", "v2": "222"},
- host: "aaa.bbb.ccc",
- path: "/111/222/333",
- shouldMatch: false,
- },
- {
- title: "Host and Path route with multiple patterns, match",
- route: new(Route).Host("{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}").Path("/{v4:[0-9]{3}}/{v5:[0-9]{3}}/{v6:[0-9]{3}}"),
- request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
- vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc", "v4": "111", "v5": "222", "v6": "333"},
- host: "aaa.bbb.ccc",
- path: "/111/222/333",
- shouldMatch: true,
- },
- {
- title: "Host and Path route with multiple patterns, URL in request does not match",
- route: new(Route).Host("{v1:[a-z]{3}}.{v2:[a-z]{3}}.{v3:[a-z]{3}}").Path("/{v4:[0-9]{3}}/{v5:[0-9]{3}}/{v6:[0-9]{3}}"),
- request: newRequest("GET", "http://aaa.222.ccc/111/222/333"),
- vars: map[string]string{"v1": "aaa", "v2": "bbb", "v3": "ccc", "v4": "111", "v5": "222", "v6": "333"},
- host: "aaa.bbb.ccc",
- path: "/111/222/333",
- shouldMatch: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestHeaders(t *testing.T) {
- // newRequestHeaders creates a new request with a method, url, and headers
- newRequestHeaders := func(method, url string, headers map[string]string) *http.Request {
- req, err := http.NewRequest(method, url, nil)
- if err != nil {
- panic(err)
- }
- for k, v := range headers {
- req.Header.Add(k, v)
- }
- return req
- }
-
- tests := []routeTest{
- {
- title: "Headers route, match",
- route: new(Route).Headers("foo", "bar", "baz", "ding"),
- request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "bar", "baz": "ding"}),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Headers route, bad header values",
- route: new(Route).Headers("foo", "bar", "baz", "ding"),
- request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "bar", "baz": "dong"}),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Headers route, regex header values to match",
- route: new(Route).Headers("foo", "ba[zr]"),
- request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "bar"}),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Headers route, regex header values to match",
- route: new(Route).HeadersRegexp("foo", "ba[zr]"),
- request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "baz"}),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-
-}
-
-func TestMethods(t *testing.T) {
- tests := []routeTest{
- {
- title: "Methods route, match GET",
- route: new(Route).Methods("GET", "POST"),
- request: newRequest("GET", "http://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Methods route, match POST",
- route: new(Route).Methods("GET", "POST"),
- request: newRequest("POST", "http://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Methods route, bad method",
- route: new(Route).Methods("GET", "POST"),
- request: newRequest("PUT", "http://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestQueries(t *testing.T) {
- tests := []routeTest{
- {
- title: "Queries route, match",
- route: new(Route).Queries("foo", "bar", "baz", "ding"),
- request: newRequest("GET", "http://localhost?foo=bar&baz=ding"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route, match with a query string",
- route: new(Route).Host("www.example.com").Path("/api").Queries("foo", "bar", "baz", "ding"),
- request: newRequest("GET", "http://www.example.com/api?foo=bar&baz=ding"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route, match with a query string out of order",
- route: new(Route).Host("www.example.com").Path("/api").Queries("foo", "bar", "baz", "ding"),
- request: newRequest("GET", "http://www.example.com/api?baz=ding&foo=bar"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route, bad query",
- route: new(Route).Queries("foo", "bar", "baz", "ding"),
- request: newRequest("GET", "http://localhost?foo=bar&baz=dong"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with pattern, match",
- route: new(Route).Queries("foo", "{v1}"),
- request: newRequest("GET", "http://localhost?foo=bar"),
- vars: map[string]string{"v1": "bar"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with multiple patterns, match",
- route: new(Route).Queries("foo", "{v1}", "baz", "{v2}"),
- request: newRequest("GET", "http://localhost?foo=bar&baz=ding"),
- vars: map[string]string{"v1": "bar", "v2": "ding"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with regexp pattern, match",
- route: new(Route).Queries("foo", "{v1:[0-9]+}"),
- request: newRequest("GET", "http://localhost?foo=10"),
- vars: map[string]string{"v1": "10"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with regexp pattern, regexp does not match",
- route: new(Route).Queries("foo", "{v1:[0-9]+}"),
- request: newRequest("GET", "http://localhost?foo=a"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with regexp pattern with quantifier, match",
- route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
- request: newRequest("GET", "http://localhost?foo=1"),
- vars: map[string]string{"v1": "1"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with regexp pattern with quantifier, additional variable in query string, match",
- route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
- request: newRequest("GET", "http://localhost?bar=2&foo=1"),
- vars: map[string]string{"v1": "1"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with regexp pattern with quantifier, regexp does not match",
- route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
- request: newRequest("GET", "http://localhost?foo=12"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with regexp pattern with quantifier, additional capturing group",
- route: new(Route).Queries("foo", "{v1:[0-9]{1}(a|b)}"),
- request: newRequest("GET", "http://localhost?foo=1a"),
- vars: map[string]string{"v1": "1a"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with regexp pattern with quantifier, additional variable in query string, regexp does not match",
- route: new(Route).Queries("foo", "{v1:[0-9]{1}}"),
- request: newRequest("GET", "http://localhost?foo=12"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with hyphenated name, match",
- route: new(Route).Queries("foo", "{v-1}"),
- request: newRequest("GET", "http://localhost?foo=bar"),
- vars: map[string]string{"v-1": "bar"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with multiple hyphenated names, match",
- route: new(Route).Queries("foo", "{v-1}", "baz", "{v-2}"),
- request: newRequest("GET", "http://localhost?foo=bar&baz=ding"),
- vars: map[string]string{"v-1": "bar", "v-2": "ding"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with hyphenate name and pattern, match",
- route: new(Route).Queries("foo", "{v-1:[0-9]+}"),
- request: newRequest("GET", "http://localhost?foo=10"),
- vars: map[string]string{"v-1": "10"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with hyphenated name and pattern with quantifier, additional capturing group",
- route: new(Route).Queries("foo", "{v-1:[0-9]{1}(a|b)}"),
- request: newRequest("GET", "http://localhost?foo=1a"),
- vars: map[string]string{"v-1": "1a"},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with empty value, should match",
- route: new(Route).Queries("foo", ""),
- request: newRequest("GET", "http://localhost?foo=bar"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with empty value and no parameter in request, should not match",
- route: new(Route).Queries("foo", ""),
- request: newRequest("GET", "http://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with empty value and empty parameter in request, should match",
- route: new(Route).Queries("foo", ""),
- request: newRequest("GET", "http://localhost?foo="),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route with overlapping value, should not match",
- route: new(Route).Queries("foo", "bar"),
- request: newRequest("GET", "http://localhost?foo=barfoo"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with no parameter in request, should not match",
- route: new(Route).Queries("foo", "{bar}"),
- request: newRequest("GET", "http://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- {
- title: "Queries route with empty parameter in request, should match",
- route: new(Route).Queries("foo", "{bar}"),
- request: newRequest("GET", "http://localhost?foo="),
- vars: map[string]string{"foo": ""},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Queries route, bad submatch",
- route: new(Route).Queries("foo", "bar", "baz", "ding"),
- request: newRequest("GET", "http://localhost?fffoo=bar&baz=dingggg"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestSchemes(t *testing.T) {
- tests := []routeTest{
- // Schemes
- {
- title: "Schemes route, match https",
- route: new(Route).Schemes("https", "ftp"),
- request: newRequest("GET", "https://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Schemes route, match ftp",
- route: new(Route).Schemes("https", "ftp"),
- request: newRequest("GET", "ftp://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "Schemes route, bad scheme",
- route: new(Route).Schemes("https", "ftp"),
- request: newRequest("GET", "http://localhost"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- }
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestMatcherFunc(t *testing.T) {
- m := func(r *http.Request, m *RouteMatch) bool {
- if r.URL.Host == "aaa.bbb.ccc" {
- return true
- }
- return false
- }
-
- tests := []routeTest{
- {
- title: "MatchFunc route, match",
- route: new(Route).MatcherFunc(m),
- request: newRequest("GET", "http://aaa.bbb.ccc"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: true,
- },
- {
- title: "MatchFunc route, non-match",
- route: new(Route).MatcherFunc(m),
- request: newRequest("GET", "http://aaa.222.ccc"),
- vars: map[string]string{},
- host: "",
- path: "",
- shouldMatch: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestBuildVarsFunc(t *testing.T) {
- tests := []routeTest{
- {
- title: "BuildVarsFunc set on route",
- route: new(Route).Path(`/111/{v1:\d}{v2:.*}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
- vars["v1"] = "3"
- vars["v2"] = "a"
- return vars
- }),
- request: newRequest("GET", "http://localhost/111/2"),
- path: "/111/3a",
- shouldMatch: true,
- },
- {
- title: "BuildVarsFunc set on route and parent route",
- route: new(Route).PathPrefix(`/{v1:\d}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
- vars["v1"] = "2"
- return vars
- }).Subrouter().Path(`/{v2:\w}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
- vars["v2"] = "b"
- return vars
- }),
- request: newRequest("GET", "http://localhost/1/a"),
- path: "/2/b",
- shouldMatch: true,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestSubRouter(t *testing.T) {
- subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter()
- subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter()
-
- tests := []routeTest{
- {
- route: subrouter1.Path("/{v2:[a-z]+}"),
- request: newRequest("GET", "http://aaa.google.com/bbb"),
- vars: map[string]string{"v1": "aaa", "v2": "bbb"},
- host: "aaa.google.com",
- path: "/bbb",
- shouldMatch: true,
- },
- {
- route: subrouter1.Path("/{v2:[a-z]+}"),
- request: newRequest("GET", "http://111.google.com/111"),
- vars: map[string]string{"v1": "aaa", "v2": "bbb"},
- host: "aaa.google.com",
- path: "/bbb",
- shouldMatch: false,
- },
- {
- route: subrouter2.Path("/baz/{v2}"),
- request: newRequest("GET", "http://localhost/foo/bar/baz/ding"),
- vars: map[string]string{"v1": "bar", "v2": "ding"},
- host: "",
- path: "/foo/bar/baz/ding",
- shouldMatch: true,
- },
- {
- route: subrouter2.Path("/baz/{v2}"),
- request: newRequest("GET", "http://localhost/foo/bar"),
- vars: map[string]string{"v1": "bar", "v2": "ding"},
- host: "",
- path: "/foo/bar/baz/ding",
- shouldMatch: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestNamedRoutes(t *testing.T) {
- r1 := NewRouter()
- r1.NewRoute().Name("a")
- r1.NewRoute().Name("b")
- r1.NewRoute().Name("c")
-
- r2 := r1.NewRoute().Subrouter()
- r2.NewRoute().Name("d")
- r2.NewRoute().Name("e")
- r2.NewRoute().Name("f")
-
- r3 := r2.NewRoute().Subrouter()
- r3.NewRoute().Name("g")
- r3.NewRoute().Name("h")
- r3.NewRoute().Name("i")
-
- if r1.namedRoutes == nil || len(r1.namedRoutes) != 9 {
- t.Errorf("Expected 9 named routes, got %v", r1.namedRoutes)
- } else if r1.Get("i") == nil {
- t.Errorf("Subroute name not registered")
- }
-}
-
-func TestStrictSlash(t *testing.T) {
- r := NewRouter()
- r.StrictSlash(true)
-
- tests := []routeTest{
- {
- title: "Redirect path without slash",
- route: r.NewRoute().Path("/111/"),
- request: newRequest("GET", "http://localhost/111"),
- vars: map[string]string{},
- host: "",
- path: "/111/",
- shouldMatch: true,
- shouldRedirect: true,
- },
- {
- title: "Do not redirect path with slash",
- route: r.NewRoute().Path("/111/"),
- request: newRequest("GET", "http://localhost/111/"),
- vars: map[string]string{},
- host: "",
- path: "/111/",
- shouldMatch: true,
- shouldRedirect: false,
- },
- {
- title: "Redirect path with slash",
- route: r.NewRoute().Path("/111"),
- request: newRequest("GET", "http://localhost/111/"),
- vars: map[string]string{},
- host: "",
- path: "/111",
- shouldMatch: true,
- shouldRedirect: true,
- },
- {
- title: "Do not redirect path without slash",
- route: r.NewRoute().Path("/111"),
- request: newRequest("GET", "http://localhost/111"),
- vars: map[string]string{},
- host: "",
- path: "/111",
- shouldMatch: true,
- shouldRedirect: false,
- },
- {
- title: "Propagate StrictSlash to subrouters",
- route: r.NewRoute().PathPrefix("/static/").Subrouter().Path("/images/"),
- request: newRequest("GET", "http://localhost/static/images"),
- vars: map[string]string{},
- host: "",
- path: "/static/images/",
- shouldMatch: true,
- shouldRedirect: true,
- },
- {
- title: "Ignore StrictSlash for path prefix",
- route: r.NewRoute().PathPrefix("/static/"),
- request: newRequest("GET", "http://localhost/static/logo.png"),
- vars: map[string]string{},
- host: "",
- path: "/static/",
- shouldMatch: true,
- shouldRedirect: false,
- },
- }
-
- for _, test := range tests {
- testRoute(t, test)
- }
-}
-
-func TestWalkSingleDepth(t *testing.T) {
- r0 := NewRouter()
- r1 := NewRouter()
- r2 := NewRouter()
-
- r0.Path("/g")
- r0.Path("/o")
- r0.Path("/d").Handler(r1)
- r0.Path("/r").Handler(r2)
- r0.Path("/a")
-
- r1.Path("/z")
- r1.Path("/i")
- r1.Path("/l")
- r1.Path("/l")
-
- r2.Path("/i")
- r2.Path("/l")
- r2.Path("/l")
-
- paths := []string{"g", "o", "r", "i", "l", "l", "a"}
- depths := []int{0, 0, 0, 1, 1, 1, 0}
- i := 0
- err := r0.Walk(func(route *Route, router *Router, ancestors []*Route) error {
- matcher := route.matchers[0].(*routeRegexp)
- if matcher.template == "/d" {
- return SkipRouter
- }
- if len(ancestors) != depths[i] {
- t.Errorf(`Expected depth of %d at i = %d; got "%d"`, depths[i], i, len(ancestors))
- }
- if matcher.template != "/"+paths[i] {
- t.Errorf(`Expected "/%s" at i = %d; got "%s"`, paths[i], i, matcher.template)
- }
- i++
- return nil
- })
- if err != nil {
- panic(err)
- }
- if i != len(paths) {
- t.Errorf("Expected %d routes, found %d", len(paths), i)
- }
-}
-
-func TestWalkNested(t *testing.T) {
- router := NewRouter()
-
- g := router.Path("/g").Subrouter()
- o := g.PathPrefix("/o").Subrouter()
- r := o.PathPrefix("/r").Subrouter()
- i := r.PathPrefix("/i").Subrouter()
- l1 := i.PathPrefix("/l").Subrouter()
- l2 := l1.PathPrefix("/l").Subrouter()
- l2.Path("/a")
-
- paths := []string{"/g", "/g/o", "/g/o/r", "/g/o/r/i", "/g/o/r/i/l", "/g/o/r/i/l/l", "/g/o/r/i/l/l/a"}
- idx := 0
- err := router.Walk(func(route *Route, router *Router, ancestors []*Route) error {
- path := paths[idx]
- tpl := route.regexp.path.template
- if tpl != path {
- t.Errorf(`Expected %s got %s`, path, tpl)
- }
- idx++
- return nil
- })
- if err != nil {
- panic(err)
- }
- if idx != len(paths) {
- t.Errorf("Expected %d routes, found %d", len(paths), idx)
- }
-}
-
-// ----------------------------------------------------------------------------
-// Helpers
-// ----------------------------------------------------------------------------
-
-func getRouteTemplate(route *Route) string {
- host, path := "none", "none"
- if route.regexp != nil {
- if route.regexp.host != nil {
- host = route.regexp.host.template
- }
- if route.regexp.path != nil {
- path = route.regexp.path.template
- }
- }
- return fmt.Sprintf("Host: %v, Path: %v", host, path)
-}
-
-func testRoute(t *testing.T, test routeTest) {
- request := test.request
- route := test.route
- vars := test.vars
- shouldMatch := test.shouldMatch
- host := test.host
- path := test.path
- url := test.host + test.path
- shouldRedirect := test.shouldRedirect
-
- var match RouteMatch
- ok := route.Match(request, &match)
- if ok != shouldMatch {
- msg := "Should match"
- if !shouldMatch {
- msg = "Should not match"
- }
- t.Errorf("(%v) %v:\nRoute: %#v\nRequest: %#v\nVars: %v\n", test.title, msg, route, request, vars)
- return
- }
- if shouldMatch {
- if test.vars != nil && !stringMapEqual(test.vars, match.Vars) {
- t.Errorf("(%v) Vars not equal: expected %v, got %v", test.title, vars, match.Vars)
- return
- }
- if host != "" {
- u, _ := test.route.URLHost(mapToPairs(match.Vars)...)
- if host != u.Host {
- t.Errorf("(%v) URLHost not equal: expected %v, got %v -- %v", test.title, host, u.Host, getRouteTemplate(route))
- return
- }
- }
- if path != "" {
- u, _ := route.URLPath(mapToPairs(match.Vars)...)
- if path != u.Path {
- t.Errorf("(%v) URLPath not equal: expected %v, got %v -- %v", test.title, path, u.Path, getRouteTemplate(route))
- return
- }
- }
- if url != "" {
- u, _ := route.URL(mapToPairs(match.Vars)...)
- if url != u.Host+u.Path {
- t.Errorf("(%v) URL not equal: expected %v, got %v -- %v", test.title, url, u.Host+u.Path, getRouteTemplate(route))
- return
- }
- }
- if shouldRedirect && match.Handler == nil {
- t.Errorf("(%v) Did not redirect", test.title)
- return
- }
- if !shouldRedirect && match.Handler != nil {
- t.Errorf("(%v) Unexpected redirect", test.title)
- return
- }
- }
-}
-
-// Tests that the context is cleared or not cleared properly depending on
-// the configuration of the router
-func TestKeepContext(t *testing.T) {
- func1 := func(w http.ResponseWriter, r *http.Request) {}
-
- r := NewRouter()
- r.HandleFunc("/", func1).Name("func1")
-
- req, _ := http.NewRequest("GET", "http://localhost/", nil)
- context.Set(req, "t", 1)
-
- res := new(http.ResponseWriter)
- r.ServeHTTP(*res, req)
-
- if _, ok := context.GetOk(req, "t"); ok {
- t.Error("Context should have been cleared at end of request")
- }
-
- r.KeepContext = true
-
- req, _ = http.NewRequest("GET", "http://localhost/", nil)
- context.Set(req, "t", 1)
-
- r.ServeHTTP(*res, req)
- if _, ok := context.GetOk(req, "t"); !ok {
- t.Error("Context should NOT have been cleared at end of request")
- }
-
-}
-
-type TestA301ResponseWriter struct {
- hh http.Header
- status int
-}
-
-func (ho TestA301ResponseWriter) Header() http.Header {
- return http.Header(ho.hh)
-}
-
-func (ho TestA301ResponseWriter) Write(b []byte) (int, error) {
- return 0, nil
-}
-
-func (ho TestA301ResponseWriter) WriteHeader(code int) {
- ho.status = code
-}
-
-func Test301Redirect(t *testing.T) {
- m := make(http.Header)
-
- func1 := func(w http.ResponseWriter, r *http.Request) {}
- func2 := func(w http.ResponseWriter, r *http.Request) {}
-
- r := NewRouter()
- r.HandleFunc("/api/", func2).Name("func2")
- r.HandleFunc("/", func1).Name("func1")
-
- req, _ := http.NewRequest("GET", "http://localhost//api/?abc=def", nil)
-
- res := TestA301ResponseWriter{
- hh: m,
- status: 0,
- }
- r.ServeHTTP(&res, req)
-
- if "http://localhost/api/?abc=def" != res.hh["Location"][0] {
- t.Errorf("Should have complete URL with query string")
- }
-}
-
-// https://plus.google.com/101022900381697718949/posts/eWy6DjFJ6uW
-func TestSubrouterHeader(t *testing.T) {
- expected := "func1 response"
- func1 := func(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, expected)
- }
- func2 := func(http.ResponseWriter, *http.Request) {}
-
- r := NewRouter()
- s := r.Headers("SomeSpecialHeader", "").Subrouter()
- s.HandleFunc("/", func1).Name("func1")
- r.HandleFunc("/", func2).Name("func2")
-
- req, _ := http.NewRequest("GET", "http://localhost/", nil)
- req.Header.Add("SomeSpecialHeader", "foo")
- match := new(RouteMatch)
- matched := r.Match(req, match)
- if !matched {
- t.Errorf("Should match request")
- }
- if match.Route.GetName() != "func1" {
- t.Errorf("Expecting func1 handler, got %s", match.Route.GetName())
- }
- resp := NewRecorder()
- match.Handler.ServeHTTP(resp, req)
- if resp.Body.String() != expected {
- t.Errorf("Expecting %q", expected)
- }
-}
-
-// mapToPairs converts a string map to a slice of string pairs
-func mapToPairs(m map[string]string) []string {
- var i int
- p := make([]string, len(m)*2)
- for k, v := range m {
- p[i] = k
- p[i+1] = v
- i += 2
- }
- return p
-}
-
-// stringMapEqual checks the equality of two string maps
-func stringMapEqual(m1, m2 map[string]string) bool {
- nil1 := m1 == nil
- nil2 := m2 == nil
- if nil1 != nil2 || len(m1) != len(m2) {
- return false
- }
- for k, v := range m1 {
- if v != m2[k] {
- return false
- }
- }
- return true
-}
-
-// newRequest is a helper function to create a new request with a method and url
-func newRequest(method, url string) *http.Request {
- req, err := http.NewRequest(method, url, nil)
- if err != nil {
- panic(err)
- }
- return req
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/old_test.go b/Godeps/_workspace/src/github.com/gorilla/mux/old_test.go
deleted file mode 100644
index 755db483e..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/mux/old_test.go
+++ /dev/null
@@ -1,714 +0,0 @@
-// Old tests ported to Go1. This is a mess. Want to drop it one day.
-
-// Copyright 2011 Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mux
-
-import (
- "bytes"
- "net/http"
- "testing"
-)
-
-// ----------------------------------------------------------------------------
-// ResponseRecorder
-// ----------------------------------------------------------------------------
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// ResponseRecorder is an implementation of http.ResponseWriter that
-// records its mutations for later inspection in tests.
-type ResponseRecorder struct {
- Code int // the HTTP response code from WriteHeader
- HeaderMap http.Header // the HTTP response headers
- Body *bytes.Buffer // if non-nil, the bytes.Buffer to append written data to
- Flushed bool
-}
-
-// NewRecorder returns an initialized ResponseRecorder.
-func NewRecorder() *ResponseRecorder {
- return &ResponseRecorder{
- HeaderMap: make(http.Header),
- Body: new(bytes.Buffer),
- }
-}
-
-// DefaultRemoteAddr is the default remote address to return in RemoteAddr if
-// an explicit DefaultRemoteAddr isn't set on ResponseRecorder.
-const DefaultRemoteAddr = "1.2.3.4"
-
-// Header returns the response headers.
-func (rw *ResponseRecorder) Header() http.Header {
- return rw.HeaderMap
-}
-
-// Write always succeeds and writes to rw.Body, if not nil.
-func (rw *ResponseRecorder) Write(buf []byte) (int, error) {
- if rw.Body != nil {
- rw.Body.Write(buf)
- }
- if rw.Code == 0 {
- rw.Code = http.StatusOK
- }
- return len(buf), nil
-}
-
-// WriteHeader sets rw.Code.
-func (rw *ResponseRecorder) WriteHeader(code int) {
- rw.Code = code
-}
-
-// Flush sets rw.Flushed to true.
-func (rw *ResponseRecorder) Flush() {
- rw.Flushed = true
-}
-
-// ----------------------------------------------------------------------------
-
-func TestRouteMatchers(t *testing.T) {
- var scheme, host, path, query, method string
- var headers map[string]string
- var resultVars map[bool]map[string]string
-
- router := NewRouter()
- router.NewRoute().Host("{var1}.google.com").
- Path("/{var2:[a-z]+}/{var3:[0-9]+}").
- Queries("foo", "bar").
- Methods("GET").
- Schemes("https").
- Headers("x-requested-with", "XMLHttpRequest")
- router.NewRoute().Host("www.{var4}.com").
- PathPrefix("/foo/{var5:[a-z]+}/{var6:[0-9]+}").
- Queries("baz", "ding").
- Methods("POST").
- Schemes("http").
- Headers("Content-Type", "application/json")
-
- reset := func() {
- // Everything match.
- scheme = "https"
- host = "www.google.com"
- path = "/product/42"
- query = "?foo=bar"
- method = "GET"
- headers = map[string]string{"X-Requested-With": "XMLHttpRequest"}
- resultVars = map[bool]map[string]string{
- true: {"var1": "www", "var2": "product", "var3": "42"},
- false: {},
- }
- }
-
- reset2 := func() {
- // Everything match.
- scheme = "http"
- host = "www.google.com"
- path = "/foo/product/42/path/that/is/ignored"
- query = "?baz=ding"
- method = "POST"
- headers = map[string]string{"Content-Type": "application/json"}
- resultVars = map[bool]map[string]string{
- true: {"var4": "google", "var5": "product", "var6": "42"},
- false: {},
- }
- }
-
- match := func(shouldMatch bool) {
- url := scheme + "://" + host + path + query
- request, _ := http.NewRequest(method, url, nil)
- for key, value := range headers {
- request.Header.Add(key, value)
- }
-
- var routeMatch RouteMatch
- matched := router.Match(request, &routeMatch)
- if matched != shouldMatch {
- // Need better messages. :)
- if matched {
- t.Errorf("Should match.")
- } else {
- t.Errorf("Should not match.")
- }
- }
-
- if matched {
- currentRoute := routeMatch.Route
- if currentRoute == nil {
- t.Errorf("Expected a current route.")
- }
- vars := routeMatch.Vars
- expectedVars := resultVars[shouldMatch]
- if len(vars) != len(expectedVars) {
- t.Errorf("Expected vars: %v Got: %v.", expectedVars, vars)
- }
- for name, value := range vars {
- if expectedVars[name] != value {
- t.Errorf("Expected vars: %v Got: %v.", expectedVars, vars)
- }
- }
- }
- }
-
- // 1st route --------------------------------------------------------------
-
- // Everything match.
- reset()
- match(true)
-
- // Scheme doesn't match.
- reset()
- scheme = "http"
- match(false)
-
- // Host doesn't match.
- reset()
- host = "www.mygoogle.com"
- match(false)
-
- // Path doesn't match.
- reset()
- path = "/product/notdigits"
- match(false)
-
- // Query doesn't match.
- reset()
- query = "?foo=baz"
- match(false)
-
- // Method doesn't match.
- reset()
- method = "POST"
- match(false)
-
- // Header doesn't match.
- reset()
- headers = map[string]string{}
- match(false)
-
- // Everything match, again.
- reset()
- match(true)
-
- // 2nd route --------------------------------------------------------------
-
- // Everything match.
- reset2()
- match(true)
-
- // Scheme doesn't match.
- reset2()
- scheme = "https"
- match(false)
-
- // Host doesn't match.
- reset2()
- host = "sub.google.com"
- match(false)
-
- // Path doesn't match.
- reset2()
- path = "/bar/product/42"
- match(false)
-
- // Query doesn't match.
- reset2()
- query = "?foo=baz"
- match(false)
-
- // Method doesn't match.
- reset2()
- method = "GET"
- match(false)
-
- // Header doesn't match.
- reset2()
- headers = map[string]string{}
- match(false)
-
- // Everything match, again.
- reset2()
- match(true)
-}
-
-type headerMatcherTest struct {
- matcher headerMatcher
- headers map[string]string
- result bool
-}
-
-var headerMatcherTests = []headerMatcherTest{
- {
- matcher: headerMatcher(map[string]string{"x-requested-with": "XMLHttpRequest"}),
- headers: map[string]string{"X-Requested-With": "XMLHttpRequest"},
- result: true,
- },
- {
- matcher: headerMatcher(map[string]string{"x-requested-with": ""}),
- headers: map[string]string{"X-Requested-With": "anything"},
- result: true,
- },
- {
- matcher: headerMatcher(map[string]string{"x-requested-with": "XMLHttpRequest"}),
- headers: map[string]string{},
- result: false,
- },
-}
-
-type hostMatcherTest struct {
- matcher *Route
- url string
- vars map[string]string
- result bool
-}
-
-var hostMatcherTests = []hostMatcherTest{
- {
- matcher: NewRouter().NewRoute().Host("{foo:[a-z][a-z][a-z]}.{bar:[a-z][a-z][a-z]}.{baz:[a-z][a-z][a-z]}"),
- url: "http://abc.def.ghi/",
- vars: map[string]string{"foo": "abc", "bar": "def", "baz": "ghi"},
- result: true,
- },
- {
- matcher: NewRouter().NewRoute().Host("{foo:[a-z][a-z][a-z]}.{bar:[a-z][a-z][a-z]}.{baz:[a-z][a-z][a-z]}"),
- url: "http://a.b.c/",
- vars: map[string]string{"foo": "abc", "bar": "def", "baz": "ghi"},
- result: false,
- },
-}
-
-type methodMatcherTest struct {
- matcher methodMatcher
- method string
- result bool
-}
-
-var methodMatcherTests = []methodMatcherTest{
- {
- matcher: methodMatcher([]string{"GET", "POST", "PUT"}),
- method: "GET",
- result: true,
- },
- {
- matcher: methodMatcher([]string{"GET", "POST", "PUT"}),
- method: "POST",
- result: true,
- },
- {
- matcher: methodMatcher([]string{"GET", "POST", "PUT"}),
- method: "PUT",
- result: true,
- },
- {
- matcher: methodMatcher([]string{"GET", "POST", "PUT"}),
- method: "DELETE",
- result: false,
- },
-}
-
-type pathMatcherTest struct {
- matcher *Route
- url string
- vars map[string]string
- result bool
-}
-
-var pathMatcherTests = []pathMatcherTest{
- {
- matcher: NewRouter().NewRoute().Path("/{foo:[0-9][0-9][0-9]}/{bar:[0-9][0-9][0-9]}/{baz:[0-9][0-9][0-9]}"),
- url: "http://localhost:8080/123/456/789",
- vars: map[string]string{"foo": "123", "bar": "456", "baz": "789"},
- result: true,
- },
- {
- matcher: NewRouter().NewRoute().Path("/{foo:[0-9][0-9][0-9]}/{bar:[0-9][0-9][0-9]}/{baz:[0-9][0-9][0-9]}"),
- url: "http://localhost:8080/1/2/3",
- vars: map[string]string{"foo": "123", "bar": "456", "baz": "789"},
- result: false,
- },
-}
-
-type schemeMatcherTest struct {
- matcher schemeMatcher
- url string
- result bool
-}
-
-var schemeMatcherTests = []schemeMatcherTest{
- {
- matcher: schemeMatcher([]string{"http", "https"}),
- url: "http://localhost:8080/",
- result: true,
- },
- {
- matcher: schemeMatcher([]string{"http", "https"}),
- url: "https://localhost:8080/",
- result: true,
- },
- {
- matcher: schemeMatcher([]string{"https"}),
- url: "http://localhost:8080/",
- result: false,
- },
- {
- matcher: schemeMatcher([]string{"http"}),
- url: "https://localhost:8080/",
- result: false,
- },
-}
-
-type urlBuildingTest struct {
- route *Route
- vars []string
- url string
-}
-
-var urlBuildingTests = []urlBuildingTest{
- {
- route: new(Route).Host("foo.domain.com"),
- vars: []string{},
- url: "http://foo.domain.com",
- },
- {
- route: new(Route).Host("{subdomain}.domain.com"),
- vars: []string{"subdomain", "bar"},
- url: "http://bar.domain.com",
- },
- {
- route: new(Route).Host("foo.domain.com").Path("/articles"),
- vars: []string{},
- url: "http://foo.domain.com/articles",
- },
- {
- route: new(Route).Path("/articles"),
- vars: []string{},
- url: "/articles",
- },
- {
- route: new(Route).Path("/articles/{category}/{id:[0-9]+}"),
- vars: []string{"category", "technology", "id", "42"},
- url: "/articles/technology/42",
- },
- {
- route: new(Route).Host("{subdomain}.domain.com").Path("/articles/{category}/{id:[0-9]+}"),
- vars: []string{"subdomain", "foo", "category", "technology", "id", "42"},
- url: "http://foo.domain.com/articles/technology/42",
- },
-}
-
-func TestHeaderMatcher(t *testing.T) {
- for _, v := range headerMatcherTests {
- request, _ := http.NewRequest("GET", "http://localhost:8080/", nil)
- for key, value := range v.headers {
- request.Header.Add(key, value)
- }
- var routeMatch RouteMatch
- result := v.matcher.Match(request, &routeMatch)
- if result != v.result {
- if v.result {
- t.Errorf("%#v: should match %v.", v.matcher, request.Header)
- } else {
- t.Errorf("%#v: should not match %v.", v.matcher, request.Header)
- }
- }
- }
-}
-
-func TestHostMatcher(t *testing.T) {
- for _, v := range hostMatcherTests {
- request, _ := http.NewRequest("GET", v.url, nil)
- var routeMatch RouteMatch
- result := v.matcher.Match(request, &routeMatch)
- vars := routeMatch.Vars
- if result != v.result {
- if v.result {
- t.Errorf("%#v: should match %v.", v.matcher, v.url)
- } else {
- t.Errorf("%#v: should not match %v.", v.matcher, v.url)
- }
- }
- if result {
- if len(vars) != len(v.vars) {
- t.Errorf("%#v: vars length should be %v, got %v.", v.matcher, len(v.vars), len(vars))
- }
- for name, value := range vars {
- if v.vars[name] != value {
- t.Errorf("%#v: expected value %v for key %v, got %v.", v.matcher, v.vars[name], name, value)
- }
- }
- } else {
- if len(vars) != 0 {
- t.Errorf("%#v: vars length should be 0, got %v.", v.matcher, len(vars))
- }
- }
- }
-}
-
-func TestMethodMatcher(t *testing.T) {
- for _, v := range methodMatcherTests {
- request, _ := http.NewRequest(v.method, "http://localhost:8080/", nil)
- var routeMatch RouteMatch
- result := v.matcher.Match(request, &routeMatch)
- if result != v.result {
- if v.result {
- t.Errorf("%#v: should match %v.", v.matcher, v.method)
- } else {
- t.Errorf("%#v: should not match %v.", v.matcher, v.method)
- }
- }
- }
-}
-
-func TestPathMatcher(t *testing.T) {
- for _, v := range pathMatcherTests {
- request, _ := http.NewRequest("GET", v.url, nil)
- var routeMatch RouteMatch
- result := v.matcher.Match(request, &routeMatch)
- vars := routeMatch.Vars
- if result != v.result {
- if v.result {
- t.Errorf("%#v: should match %v.", v.matcher, v.url)
- } else {
- t.Errorf("%#v: should not match %v.", v.matcher, v.url)
- }
- }
- if result {
- if len(vars) != len(v.vars) {
- t.Errorf("%#v: vars length should be %v, got %v.", v.matcher, len(v.vars), len(vars))
- }
- for name, value := range vars {
- if v.vars[name] != value {
- t.Errorf("%#v: expected value %v for key %v, got %v.", v.matcher, v.vars[name], name, value)
- }
- }
- } else {
- if len(vars) != 0 {
- t.Errorf("%#v: vars length should be 0, got %v.", v.matcher, len(vars))
- }
- }
- }
-}
-
-func TestSchemeMatcher(t *testing.T) {
- for _, v := range schemeMatcherTests {
- request, _ := http.NewRequest("GET", v.url, nil)
- var routeMatch RouteMatch
- result := v.matcher.Match(request, &routeMatch)
- if result != v.result {
- if v.result {
- t.Errorf("%#v: should match %v.", v.matcher, v.url)
- } else {
- t.Errorf("%#v: should not match %v.", v.matcher, v.url)
- }
- }
- }
-}
-
-func TestUrlBuilding(t *testing.T) {
-
- for _, v := range urlBuildingTests {
- u, _ := v.route.URL(v.vars...)
- url := u.String()
- if url != v.url {
- t.Errorf("expected %v, got %v", v.url, url)
- /*
- reversePath := ""
- reverseHost := ""
- if v.route.pathTemplate != nil {
- reversePath = v.route.pathTemplate.Reverse
- }
- if v.route.hostTemplate != nil {
- reverseHost = v.route.hostTemplate.Reverse
- }
-
- t.Errorf("%#v:\nexpected: %q\ngot: %q\nreverse path: %q\nreverse host: %q", v.route, v.url, url, reversePath, reverseHost)
- */
- }
- }
-
- ArticleHandler := func(w http.ResponseWriter, r *http.Request) {
- }
-
- router := NewRouter()
- router.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).Name("article")
-
- url, _ := router.Get("article").URL("category", "technology", "id", "42")
- expected := "/articles/technology/42"
- if url.String() != expected {
- t.Errorf("Expected %v, got %v", expected, url.String())
- }
-}
-
-func TestMatchedRouteName(t *testing.T) {
- routeName := "stock"
- router := NewRouter()
- route := router.NewRoute().Path("/products/").Name(routeName)
-
- url := "http://www.example.com/products/"
- request, _ := http.NewRequest("GET", url, nil)
- var rv RouteMatch
- ok := router.Match(request, &rv)
-
- if !ok || rv.Route != route {
- t.Errorf("Expected same route, got %+v.", rv.Route)
- }
-
- retName := rv.Route.GetName()
- if retName != routeName {
- t.Errorf("Expected %q, got %q.", routeName, retName)
- }
-}
-
-func TestSubRouting(t *testing.T) {
- // Example from docs.
- router := NewRouter()
- subrouter := router.NewRoute().Host("www.example.com").Subrouter()
- route := subrouter.NewRoute().Path("/products/").Name("products")
-
- url := "http://www.example.com/products/"
- request, _ := http.NewRequest("GET", url, nil)
- var rv RouteMatch
- ok := router.Match(request, &rv)
-
- if !ok || rv.Route != route {
- t.Errorf("Expected same route, got %+v.", rv.Route)
- }
-
- u, _ := router.Get("products").URL()
- builtUrl := u.String()
- // Yay, subroute aware of the domain when building!
- if builtUrl != url {
- t.Errorf("Expected %q, got %q.", url, builtUrl)
- }
-}
-
-func TestVariableNames(t *testing.T) {
- route := new(Route).Host("{arg1}.domain.com").Path("/{arg1}/{arg2:[0-9]+}")
- if route.err == nil {
- t.Errorf("Expected error for duplicated variable names")
- }
-}
-
-func TestRedirectSlash(t *testing.T) {
- var route *Route
- var routeMatch RouteMatch
- r := NewRouter()
-
- r.StrictSlash(false)
- route = r.NewRoute()
- if route.strictSlash != false {
- t.Errorf("Expected false redirectSlash.")
- }
-
- r.StrictSlash(true)
- route = r.NewRoute()
- if route.strictSlash != true {
- t.Errorf("Expected true redirectSlash.")
- }
-
- route = new(Route)
- route.strictSlash = true
- route.Path("/{arg1}/{arg2:[0-9]+}/")
- request, _ := http.NewRequest("GET", "http://localhost/foo/123", nil)
- routeMatch = RouteMatch{}
- _ = route.Match(request, &routeMatch)
- vars := routeMatch.Vars
- if vars["arg1"] != "foo" {
- t.Errorf("Expected foo.")
- }
- if vars["arg2"] != "123" {
- t.Errorf("Expected 123.")
- }
- rsp := NewRecorder()
- routeMatch.Handler.ServeHTTP(rsp, request)
- if rsp.HeaderMap.Get("Location") != "http://localhost/foo/123/" {
- t.Errorf("Expected redirect header.")
- }
-
- route = new(Route)
- route.strictSlash = true
- route.Path("/{arg1}/{arg2:[0-9]+}")
- request, _ = http.NewRequest("GET", "http://localhost/foo/123/", nil)
- routeMatch = RouteMatch{}
- _ = route.Match(request, &routeMatch)
- vars = routeMatch.Vars
- if vars["arg1"] != "foo" {
- t.Errorf("Expected foo.")
- }
- if vars["arg2"] != "123" {
- t.Errorf("Expected 123.")
- }
- rsp = NewRecorder()
- routeMatch.Handler.ServeHTTP(rsp, request)
- if rsp.HeaderMap.Get("Location") != "http://localhost/foo/123" {
- t.Errorf("Expected redirect header.")
- }
-}
-
-// Test for the new regexp library, still not available in stable Go.
-func TestNewRegexp(t *testing.T) {
- var p *routeRegexp
- var matches []string
-
- tests := map[string]map[string][]string{
- "/{foo:a{2}}": {
- "/a": nil,
- "/aa": {"aa"},
- "/aaa": nil,
- "/aaaa": nil,
- },
- "/{foo:a{2,}}": {
- "/a": nil,
- "/aa": {"aa"},
- "/aaa": {"aaa"},
- "/aaaa": {"aaaa"},
- },
- "/{foo:a{2,3}}": {
- "/a": nil,
- "/aa": {"aa"},
- "/aaa": {"aaa"},
- "/aaaa": nil,
- },
- "/{foo:[a-z]{3}}/{bar:[a-z]{2}}": {
- "/a": nil,
- "/ab": nil,
- "/abc": nil,
- "/abcd": nil,
- "/abc/ab": {"abc", "ab"},
- "/abc/abc": nil,
- "/abcd/ab": nil,
- },
- `/{foo:\w{3,}}/{bar:\d{2,}}`: {
- "/a": nil,
- "/ab": nil,
- "/abc": nil,
- "/abc/1": nil,
- "/abc/12": {"abc", "12"},
- "/abcd/12": {"abcd", "12"},
- "/abcd/123": {"abcd", "123"},
- },
- }
-
- for pattern, paths := range tests {
- p, _ = newRouteRegexp(pattern, false, false, false, false)
- for path, result := range paths {
- matches = p.regexp.FindStringSubmatch(path)
- if result == nil {
- if matches != nil {
- t.Errorf("%v should not match %v.", pattern, path)
- }
- } else {
- if len(matches) != len(result)+1 {
- t.Errorf("Expected %v matches, got %v.", len(result)+1, len(matches))
- } else {
- for k, v := range result {
- if matches[k+1] != v {
- t.Errorf("Expected %v, got %v.", v, matches[k+1])
- }
- }
- }
- }
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/bench_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/bench_test.go
deleted file mode 100644
index f66fc36bc..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/bench_test.go
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "testing"
-)
-
-func BenchmarkMaskBytes(b *testing.B) {
- var key [4]byte
- data := make([]byte, 1024)
- pos := 0
- for i := 0; i < b.N; i++ {
- pos = maskBytes(key, pos, data)
- }
- b.SetBytes(int64(len(data)))
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go
deleted file mode 100644
index c67550e92..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go
+++ /dev/null
@@ -1,410 +0,0 @@
-// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "crypto/tls"
- "crypto/x509"
- "io"
- "io/ioutil"
- "net"
- "net/http"
- "net/http/httptest"
- "net/url"
- "reflect"
- "strings"
- "testing"
- "time"
-)
-
-var cstUpgrader = Upgrader{
- Subprotocols: []string{"p0", "p1"},
- ReadBufferSize: 1024,
- WriteBufferSize: 1024,
- Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
- http.Error(w, reason.Error(), status)
- },
-}
-
-var cstDialer = Dialer{
- Subprotocols: []string{"p1", "p2"},
- ReadBufferSize: 1024,
- WriteBufferSize: 1024,
-}
-
-type cstHandler struct{ *testing.T }
-
-type cstServer struct {
- *httptest.Server
- URL string
-}
-
-const (
- cstPath = "/a/b"
- cstRawQuery = "x=y"
- cstRequestURI = cstPath + "?" + cstRawQuery
-)
-
-func newServer(t *testing.T) *cstServer {
- var s cstServer
- s.Server = httptest.NewServer(cstHandler{t})
- s.Server.URL += cstRequestURI
- s.URL = makeWsProto(s.Server.URL)
- return &s
-}
-
-func newTLSServer(t *testing.T) *cstServer {
- var s cstServer
- s.Server = httptest.NewTLSServer(cstHandler{t})
- s.Server.URL += cstRequestURI
- s.URL = makeWsProto(s.Server.URL)
- return &s
-}
-
-func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != cstPath {
- t.Logf("path=%v, want %v", r.URL.Path, cstPath)
- http.Error(w, "bad path", 400)
- return
- }
- if r.URL.RawQuery != cstRawQuery {
- t.Logf("query=%v, want %v", r.URL.RawQuery, cstRawQuery)
- http.Error(w, "bad path", 400)
- return
- }
- subprotos := Subprotocols(r)
- if !reflect.DeepEqual(subprotos, cstDialer.Subprotocols) {
- t.Logf("subprotols=%v, want %v", subprotos, cstDialer.Subprotocols)
- http.Error(w, "bad protocol", 400)
- return
- }
- ws, err := cstUpgrader.Upgrade(w, r, http.Header{"Set-Cookie": {"sessionID=1234"}})
- if err != nil {
- t.Logf("Upgrade: %v", err)
- return
- }
- defer ws.Close()
-
- if ws.Subprotocol() != "p1" {
- t.Logf("Subprotocol() = %s, want p1", ws.Subprotocol())
- ws.Close()
- return
- }
- op, rd, err := ws.NextReader()
- if err != nil {
- t.Logf("NextReader: %v", err)
- return
- }
- wr, err := ws.NextWriter(op)
- if err != nil {
- t.Logf("NextWriter: %v", err)
- return
- }
- if _, err = io.Copy(wr, rd); err != nil {
- t.Logf("NextWriter: %v", err)
- return
- }
- if err := wr.Close(); err != nil {
- t.Logf("Close: %v", err)
- return
- }
-}
-
-func makeWsProto(s string) string {
- return "ws" + strings.TrimPrefix(s, "http")
-}
-
-func sendRecv(t *testing.T, ws *Conn) {
- const message = "Hello World!"
- if err := ws.SetWriteDeadline(time.Now().Add(time.Second)); err != nil {
- t.Fatalf("SetWriteDeadline: %v", err)
- }
- if err := ws.WriteMessage(TextMessage, []byte(message)); err != nil {
- t.Fatalf("WriteMessage: %v", err)
- }
- if err := ws.SetReadDeadline(time.Now().Add(time.Second)); err != nil {
- t.Fatalf("SetReadDeadline: %v", err)
- }
- _, p, err := ws.ReadMessage()
- if err != nil {
- t.Fatalf("ReadMessage: %v", err)
- }
- if string(p) != message {
- t.Fatalf("message=%s, want %s", p, message)
- }
-}
-
-func TestProxyDial(t *testing.T) {
-
- s := newServer(t)
- defer s.Close()
-
- surl, _ := url.Parse(s.URL)
-
- cstDialer.Proxy = http.ProxyURL(surl)
-
- connect := false
- origHandler := s.Server.Config.Handler
-
- // Capture the request Host header.
- s.Server.Config.Handler = http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if r.Method == "CONNECT" {
- connect = true
- w.WriteHeader(200)
- return
- }
-
- if !connect {
- t.Log("connect not recieved")
- http.Error(w, "connect not recieved", 405)
- return
- }
- origHandler.ServeHTTP(w, r)
- })
-
- ws, _, err := cstDialer.Dial(s.URL, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-
- cstDialer.Proxy = http.ProxyFromEnvironment
-}
-
-func TestDial(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- ws, _, err := cstDialer.Dial(s.URL, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-}
-
-func TestDialTLS(t *testing.T) {
- s := newTLSServer(t)
- defer s.Close()
-
- certs := x509.NewCertPool()
- for _, c := range s.TLS.Certificates {
- roots, err := x509.ParseCertificates(c.Certificate[len(c.Certificate)-1])
- if err != nil {
- t.Fatalf("error parsing server's root cert: %v", err)
- }
- for _, root := range roots {
- certs.AddCert(root)
- }
- }
-
- u, _ := url.Parse(s.URL)
- d := cstDialer
- d.NetDial = func(network, addr string) (net.Conn, error) { return net.Dial(network, u.Host) }
- d.TLSClientConfig = &tls.Config{RootCAs: certs}
- ws, _, err := d.Dial("wss://example.com"+cstRequestURI, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-}
-
-func xTestDialTLSBadCert(t *testing.T) {
- // This test is deactivated because of noisy logging from the net/http package.
- s := newTLSServer(t)
- defer s.Close()
-
- ws, _, err := cstDialer.Dial(s.URL, nil)
- if err == nil {
- ws.Close()
- t.Fatalf("Dial: nil")
- }
-}
-
-func xTestDialTLSNoVerify(t *testing.T) {
- s := newTLSServer(t)
- defer s.Close()
-
- d := cstDialer
- d.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
- ws, _, err := d.Dial(s.URL, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-}
-
-func TestDialTimeout(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- d := cstDialer
- d.HandshakeTimeout = -1
- ws, _, err := d.Dial(s.URL, nil)
- if err == nil {
- ws.Close()
- t.Fatalf("Dial: nil")
- }
-}
-
-func TestDialBadScheme(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- ws, _, err := cstDialer.Dial(s.Server.URL, nil)
- if err == nil {
- ws.Close()
- t.Fatalf("Dial: nil")
- }
-}
-
-func TestDialBadOrigin(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- ws, resp, err := cstDialer.Dial(s.URL, http.Header{"Origin": {"bad"}})
- if err == nil {
- ws.Close()
- t.Fatalf("Dial: nil")
- }
- if resp == nil {
- t.Fatalf("resp=nil, err=%v", err)
- }
- if resp.StatusCode != http.StatusForbidden {
- t.Fatalf("status=%d, want %d", resp.StatusCode, http.StatusForbidden)
- }
-}
-
-func TestDialBadHeader(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- for _, k := range []string{"Upgrade",
- "Connection",
- "Sec-Websocket-Key",
- "Sec-Websocket-Version",
- "Sec-Websocket-Protocol"} {
- h := http.Header{}
- h.Set(k, "bad")
- ws, _, err := cstDialer.Dial(s.URL, http.Header{"Origin": {"bad"}})
- if err == nil {
- ws.Close()
- t.Errorf("Dial with header %s returned nil", k)
- }
- }
-}
-
-func TestBadMethod(t *testing.T) {
- s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- ws, err := cstUpgrader.Upgrade(w, r, nil)
- if err == nil {
- t.Errorf("handshake succeeded, expect fail")
- ws.Close()
- }
- }))
- defer s.Close()
-
- resp, err := http.PostForm(s.URL, url.Values{})
- if err != nil {
- t.Fatalf("PostForm returned error %v", err)
- }
- resp.Body.Close()
- if resp.StatusCode != http.StatusMethodNotAllowed {
- t.Errorf("Status = %d, want %d", resp.StatusCode, http.StatusMethodNotAllowed)
- }
-}
-
-func TestHandshake(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- ws, resp, err := cstDialer.Dial(s.URL, http.Header{"Origin": {s.URL}})
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
-
- var sessionID string
- for _, c := range resp.Cookies() {
- if c.Name == "sessionID" {
- sessionID = c.Value
- }
- }
- if sessionID != "1234" {
- t.Error("Set-Cookie not received from the server.")
- }
-
- if ws.Subprotocol() != "p1" {
- t.Errorf("ws.Subprotocol() = %s, want p1", ws.Subprotocol())
- }
- sendRecv(t, ws)
-}
-
-func TestRespOnBadHandshake(t *testing.T) {
- const expectedStatus = http.StatusGone
- const expectedBody = "This is the response body."
-
- s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(expectedStatus)
- io.WriteString(w, expectedBody)
- }))
- defer s.Close()
-
- ws, resp, err := cstDialer.Dial(makeWsProto(s.URL), nil)
- if err == nil {
- ws.Close()
- t.Fatalf("Dial: nil")
- }
-
- if resp == nil {
- t.Fatalf("resp=nil, err=%v", err)
- }
-
- if resp.StatusCode != expectedStatus {
- t.Errorf("resp.StatusCode=%d, want %d", resp.StatusCode, expectedStatus)
- }
-
- p, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Fatalf("ReadFull(resp.Body) returned error %v", err)
- }
-
- if string(p) != expectedBody {
- t.Errorf("resp.Body=%s, want %s", p, expectedBody)
- }
-}
-
-// TestHostHeader confirms that the host header provided in the call to Dial is
-// sent to the server.
-func TestHostHeader(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- specifiedHost := make(chan string, 1)
- origHandler := s.Server.Config.Handler
-
- // Capture the request Host header.
- s.Server.Config.Handler = http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- specifiedHost <- r.Host
- origHandler.ServeHTTP(w, r)
- })
-
- ws, _, err := cstDialer.Dial(s.URL, http.Header{"Host": {"testhost"}})
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
-
- if gotHost := <-specifiedHost; gotHost != "testhost" {
- t.Fatalf("gotHost = %q, want \"testhost\"", gotHost)
- }
-
- sendRecv(t, ws)
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go
deleted file mode 100644
index 7d2b0844f..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "net/url"
- "reflect"
- "testing"
-)
-
-var parseURLTests = []struct {
- s string
- u *url.URL
- rui string
-}{
- {"ws://example.com/", &url.URL{Scheme: "ws", Host: "example.com", Opaque: "/"}, "/"},
- {"ws://example.com", &url.URL{Scheme: "ws", Host: "example.com", Opaque: "/"}, "/"},
- {"ws://example.com:7777/", &url.URL{Scheme: "ws", Host: "example.com:7777", Opaque: "/"}, "/"},
- {"wss://example.com/", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/"}, "/"},
- {"wss://example.com/a/b", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/a/b"}, "/a/b"},
- {"ss://example.com/a/b", nil, ""},
- {"ws://webmaster@example.com/", nil, ""},
- {"wss://example.com/a/b?x=y", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/a/b", RawQuery: "x=y"}, "/a/b?x=y"},
- {"wss://example.com?x=y", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/", RawQuery: "x=y"}, "/?x=y"},
-}
-
-func TestParseURL(t *testing.T) {
- for _, tt := range parseURLTests {
- u, err := parseURL(tt.s)
- if tt.u != nil && err != nil {
- t.Errorf("parseURL(%q) returned error %v", tt.s, err)
- continue
- }
- if tt.u == nil {
- if err == nil {
- t.Errorf("parseURL(%q) did not return error", tt.s)
- }
- continue
- }
- if !reflect.DeepEqual(u, tt.u) {
- t.Errorf("parseURL(%q) = %v, want %v", tt.s, u, tt.u)
- continue
- }
- if u.RequestURI() != tt.rui {
- t.Errorf("parseURL(%q).RequestURI() = %v, want %v", tt.s, u.RequestURI(), tt.rui)
- }
- }
-}
-
-var hostPortNoPortTests = []struct {
- u *url.URL
- hostPort, hostNoPort string
-}{
- {&url.URL{Scheme: "ws", Host: "example.com"}, "example.com:80", "example.com"},
- {&url.URL{Scheme: "wss", Host: "example.com"}, "example.com:443", "example.com"},
- {&url.URL{Scheme: "ws", Host: "example.com:7777"}, "example.com:7777", "example.com"},
- {&url.URL{Scheme: "wss", Host: "example.com:7777"}, "example.com:7777", "example.com"},
-}
-
-func TestHostPortNoPort(t *testing.T) {
- for _, tt := range hostPortNoPortTests {
- hostPort, hostNoPort := hostPortNoPort(tt.u)
- if hostPort != tt.hostPort {
- t.Errorf("hostPortNoPort(%v) returned hostPort %q, want %q", tt.u, hostPort, tt.hostPort)
- }
- if hostNoPort != tt.hostNoPort {
- t.Errorf("hostPortNoPort(%v) returned hostNoPort %q, want %q", tt.u, hostNoPort, tt.hostNoPort)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/conn_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/conn_test.go
deleted file mode 100644
index 02f2d4b50..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/conn_test.go
+++ /dev/null
@@ -1,272 +0,0 @@
-// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "bufio"
- "bytes"
- "fmt"
- "io"
- "io/ioutil"
- "net"
- "reflect"
- "testing"
- "testing/iotest"
- "time"
-)
-
-var _ net.Error = errWriteTimeout
-
-type fakeNetConn struct {
- io.Reader
- io.Writer
-}
-
-func (c fakeNetConn) Close() error { return nil }
-func (c fakeNetConn) LocalAddr() net.Addr { return nil }
-func (c fakeNetConn) RemoteAddr() net.Addr { return nil }
-func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
-func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
-func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
-
-func TestFraming(t *testing.T) {
- frameSizes := []int{0, 1, 2, 124, 125, 126, 127, 128, 129, 65534, 65535, 65536, 65537}
- var readChunkers = []struct {
- name string
- f func(io.Reader) io.Reader
- }{
- {"half", iotest.HalfReader},
- {"one", iotest.OneByteReader},
- {"asis", func(r io.Reader) io.Reader { return r }},
- }
-
- writeBuf := make([]byte, 65537)
- for i := range writeBuf {
- writeBuf[i] = byte(i)
- }
-
- for _, isServer := range []bool{true, false} {
- for _, chunker := range readChunkers {
-
- var connBuf bytes.Buffer
- wc := newConn(fakeNetConn{Reader: nil, Writer: &connBuf}, isServer, 1024, 1024)
- rc := newConn(fakeNetConn{Reader: chunker.f(&connBuf), Writer: nil}, !isServer, 1024, 1024)
-
- for _, n := range frameSizes {
- for _, iocopy := range []bool{true, false} {
- name := fmt.Sprintf("s:%v, r:%s, n:%d c:%v", isServer, chunker.name, n, iocopy)
-
- w, err := wc.NextWriter(TextMessage)
- if err != nil {
- t.Errorf("%s: wc.NextWriter() returned %v", name, err)
- continue
- }
- var nn int
- if iocopy {
- var n64 int64
- n64, err = io.Copy(w, bytes.NewReader(writeBuf[:n]))
- nn = int(n64)
- } else {
- nn, err = w.Write(writeBuf[:n])
- }
- if err != nil || nn != n {
- t.Errorf("%s: w.Write(writeBuf[:n]) returned %d, %v", name, nn, err)
- continue
- }
- err = w.Close()
- if err != nil {
- t.Errorf("%s: w.Close() returned %v", name, err)
- continue
- }
-
- opCode, r, err := rc.NextReader()
- if err != nil || opCode != TextMessage {
- t.Errorf("%s: NextReader() returned %d, r, %v", name, opCode, err)
- continue
- }
- rbuf, err := ioutil.ReadAll(r)
- if err != nil {
- t.Errorf("%s: ReadFull() returned rbuf, %v", name, err)
- continue
- }
-
- if len(rbuf) != n {
- t.Errorf("%s: len(rbuf) is %d, want %d", name, len(rbuf), n)
- continue
- }
-
- for i, b := range rbuf {
- if byte(i) != b {
- t.Errorf("%s: bad byte at offset %d", name, i)
- break
- }
- }
- }
- }
- }
- }
-}
-
-func TestControl(t *testing.T) {
- const message = "this is a ping/pong messsage"
- for _, isServer := range []bool{true, false} {
- for _, isWriteControl := range []bool{true, false} {
- name := fmt.Sprintf("s:%v, wc:%v", isServer, isWriteControl)
- var connBuf bytes.Buffer
- wc := newConn(fakeNetConn{Reader: nil, Writer: &connBuf}, isServer, 1024, 1024)
- rc := newConn(fakeNetConn{Reader: &connBuf, Writer: nil}, !isServer, 1024, 1024)
- if isWriteControl {
- wc.WriteControl(PongMessage, []byte(message), time.Now().Add(time.Second))
- } else {
- w, err := wc.NextWriter(PongMessage)
- if err != nil {
- t.Errorf("%s: wc.NextWriter() returned %v", name, err)
- continue
- }
- if _, err := w.Write([]byte(message)); err != nil {
- t.Errorf("%s: w.Write() returned %v", name, err)
- continue
- }
- if err := w.Close(); err != nil {
- t.Errorf("%s: w.Close() returned %v", name, err)
- continue
- }
- var actualMessage string
- rc.SetPongHandler(func(s string) error { actualMessage = s; return nil })
- rc.NextReader()
- if actualMessage != message {
- t.Errorf("%s: pong=%q, want %q", name, actualMessage, message)
- continue
- }
- }
- }
- }
-}
-
-func TestCloseBeforeFinalFrame(t *testing.T) {
- const bufSize = 512
-
- expectedErr := &CloseError{Code: CloseNormalClosure, Text: "hello"}
-
- var b1, b2 bytes.Buffer
- wc := newConn(fakeNetConn{Reader: nil, Writer: &b1}, false, 1024, bufSize)
- rc := newConn(fakeNetConn{Reader: &b1, Writer: &b2}, true, 1024, 1024)
-
- w, _ := wc.NextWriter(BinaryMessage)
- w.Write(make([]byte, bufSize+bufSize/2))
- wc.WriteControl(CloseMessage, FormatCloseMessage(expectedErr.Code, expectedErr.Text), time.Now().Add(10*time.Second))
- w.Close()
-
- op, r, err := rc.NextReader()
- if op != BinaryMessage || err != nil {
- t.Fatalf("NextReader() returned %d, %v", op, err)
- }
- _, err = io.Copy(ioutil.Discard, r)
- if !reflect.DeepEqual(err, expectedErr) {
- t.Fatalf("io.Copy() returned %v, want %v", err, expectedErr)
- }
- _, _, err = rc.NextReader()
- if !reflect.DeepEqual(err, expectedErr) {
- t.Fatalf("NextReader() returned %v, want %v", err, expectedErr)
- }
-}
-
-func TestEOFBeforeFinalFrame(t *testing.T) {
- const bufSize = 512
-
- var b1, b2 bytes.Buffer
- wc := newConn(fakeNetConn{Reader: nil, Writer: &b1}, false, 1024, bufSize)
- rc := newConn(fakeNetConn{Reader: &b1, Writer: &b2}, true, 1024, 1024)
-
- w, _ := wc.NextWriter(BinaryMessage)
- w.Write(make([]byte, bufSize+bufSize/2))
-
- op, r, err := rc.NextReader()
- if op != BinaryMessage || err != nil {
- t.Fatalf("NextReader() returned %d, %v", op, err)
- }
- _, err = io.Copy(ioutil.Discard, r)
- if err != errUnexpectedEOF {
- t.Fatalf("io.Copy() returned %v, want %v", err, errUnexpectedEOF)
- }
- _, _, err = rc.NextReader()
- if err != errUnexpectedEOF {
- t.Fatalf("NextReader() returned %v, want %v", err, errUnexpectedEOF)
- }
-}
-
-func TestReadLimit(t *testing.T) {
-
- const readLimit = 512
- message := make([]byte, readLimit+1)
-
- var b1, b2 bytes.Buffer
- wc := newConn(fakeNetConn{Reader: nil, Writer: &b1}, false, 1024, readLimit-2)
- rc := newConn(fakeNetConn{Reader: &b1, Writer: &b2}, true, 1024, 1024)
- rc.SetReadLimit(readLimit)
-
- // Send message at the limit with interleaved pong.
- w, _ := wc.NextWriter(BinaryMessage)
- w.Write(message[:readLimit-1])
- wc.WriteControl(PongMessage, []byte("this is a pong"), time.Now().Add(10*time.Second))
- w.Write(message[:1])
- w.Close()
-
- // Send message larger than the limit.
- wc.WriteMessage(BinaryMessage, message[:readLimit+1])
-
- op, _, err := rc.NextReader()
- if op != BinaryMessage || err != nil {
- t.Fatalf("1: NextReader() returned %d, %v", op, err)
- }
- op, r, err := rc.NextReader()
- if op != BinaryMessage || err != nil {
- t.Fatalf("2: NextReader() returned %d, %v", op, err)
- }
- _, err = io.Copy(ioutil.Discard, r)
- if err != ErrReadLimit {
- t.Fatalf("io.Copy() returned %v", err)
- }
-}
-
-func TestUnderlyingConn(t *testing.T) {
- var b1, b2 bytes.Buffer
- fc := fakeNetConn{Reader: &b1, Writer: &b2}
- c := newConn(fc, true, 1024, 1024)
- ul := c.UnderlyingConn()
- if ul != fc {
- t.Fatalf("Underlying conn is not what it should be.")
- }
-}
-
-func TestBufioReadBytes(t *testing.T) {
-
- // Test calling bufio.ReadBytes for value longer than read buffer size.
-
- m := make([]byte, 512)
- m[len(m)-1] = '\n'
-
- var b1, b2 bytes.Buffer
- wc := newConn(fakeNetConn{Reader: nil, Writer: &b1}, false, len(m)+64, len(m)+64)
- rc := newConn(fakeNetConn{Reader: &b1, Writer: &b2}, true, len(m)-64, len(m)-64)
-
- w, _ := wc.NextWriter(BinaryMessage)
- w.Write(m)
- w.Close()
-
- op, r, err := rc.NextReader()
- if op != BinaryMessage || err != nil {
- t.Fatalf("NextReader() returned %d, %v", op, err)
- }
-
- br := bufio.NewReader(r)
- p, err := br.ReadBytes('\n')
- if err != nil {
- t.Fatalf("ReadBytes() returned %v", err)
- }
- if len(p) != len(m) {
- t.Fatalf("read returnd %d bytes, want %d bytes", len(p), len(m))
- }
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go
deleted file mode 100644
index 61100e481..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "bytes"
- "encoding/json"
- "io"
- "reflect"
- "testing"
-)
-
-func TestJSON(t *testing.T) {
- var buf bytes.Buffer
- c := fakeNetConn{&buf, &buf}
- wc := newConn(c, true, 1024, 1024)
- rc := newConn(c, false, 1024, 1024)
-
- var actual, expect struct {
- A int
- B string
- }
- expect.A = 1
- expect.B = "hello"
-
- if err := wc.WriteJSON(&expect); err != nil {
- t.Fatal("write", err)
- }
-
- if err := rc.ReadJSON(&actual); err != nil {
- t.Fatal("read", err)
- }
-
- if !reflect.DeepEqual(&actual, &expect) {
- t.Fatal("equal", actual, expect)
- }
-}
-
-func TestPartialJSONRead(t *testing.T) {
- var buf bytes.Buffer
- c := fakeNetConn{&buf, &buf}
- wc := newConn(c, true, 1024, 1024)
- rc := newConn(c, false, 1024, 1024)
-
- var v struct {
- A int
- B string
- }
- v.A = 1
- v.B = "hello"
-
- messageCount := 0
-
- // Partial JSON values.
-
- data, err := json.Marshal(v)
- if err != nil {
- t.Fatal(err)
- }
- for i := len(data) - 1; i >= 0; i-- {
- if err := wc.WriteMessage(TextMessage, data[:i]); err != nil {
- t.Fatal(err)
- }
- messageCount++
- }
-
- // Whitespace.
-
- if err := wc.WriteMessage(TextMessage, []byte(" ")); err != nil {
- t.Fatal(err)
- }
- messageCount++
-
- // Close.
-
- if err := wc.WriteMessage(CloseMessage, FormatCloseMessage(CloseNormalClosure, "")); err != nil {
- t.Fatal(err)
- }
-
- for i := 0; i < messageCount; i++ {
- err := rc.ReadJSON(&v)
- if err != io.ErrUnexpectedEOF {
- t.Error("read", i, err)
- }
- }
-
- err = rc.ReadJSON(&v)
- if _, ok := err.(*CloseError); !ok {
- t.Error("final", err)
- }
-}
-
-func TestDeprecatedJSON(t *testing.T) {
- var buf bytes.Buffer
- c := fakeNetConn{&buf, &buf}
- wc := newConn(c, true, 1024, 1024)
- rc := newConn(c, false, 1024, 1024)
-
- var actual, expect struct {
- A int
- B string
- }
- expect.A = 1
- expect.B = "hello"
-
- if err := WriteJSON(wc, &expect); err != nil {
- t.Fatal("write", err)
- }
-
- if err := ReadJSON(rc, &actual); err != nil {
- t.Fatal("read", err)
- }
-
- if !reflect.DeepEqual(&actual, &expect) {
- t.Fatal("equal", actual, expect)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/server_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/server_test.go
deleted file mode 100644
index ead0776af..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/server_test.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "net/http"
- "reflect"
- "testing"
-)
-
-var subprotocolTests = []struct {
- h string
- protocols []string
-}{
- {"", nil},
- {"foo", []string{"foo"}},
- {"foo,bar", []string{"foo", "bar"}},
- {"foo, bar", []string{"foo", "bar"}},
- {" foo, bar", []string{"foo", "bar"}},
- {" foo, bar ", []string{"foo", "bar"}},
-}
-
-func TestSubprotocols(t *testing.T) {
- for _, st := range subprotocolTests {
- r := http.Request{Header: http.Header{"Sec-Websocket-Protocol": {st.h}}}
- protocols := Subprotocols(&r)
- if !reflect.DeepEqual(st.protocols, protocols) {
- t.Errorf("SubProtocols(%q) returned %#v, want %#v", st.h, protocols, st.protocols)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/util_test.go b/Godeps/_workspace/src/github.com/gorilla/websocket/util_test.go
deleted file mode 100644
index 91f70ceb0..000000000
--- a/Godeps/_workspace/src/github.com/gorilla/websocket/util_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package websocket
-
-import (
- "net/http"
- "testing"
-)
-
-var tokenListContainsValueTests = []struct {
- value string
- ok bool
-}{
- {"WebSocket", true},
- {"WEBSOCKET", true},
- {"websocket", true},
- {"websockets", false},
- {"x websocket", false},
- {"websocket x", false},
- {"other,websocket,more", true},
- {"other, websocket, more", true},
-}
-
-func TestTokenListContainsValue(t *testing.T) {
- for _, tt := range tokenListContainsValueTests {
- h := http.Header{"Upgrade": {tt.value}}
- ok := tokenListContainsValue(h, "Upgrade", "websocket")
- if ok != tt.ok {
- t.Errorf("tokenListContainsValue(h, n, %q) = %v, want %v", tt.value, ok, tt.ok)
- }
- }
-}