Skip to content

Commit 9007e29

Browse files
committed
Add test for function tokenListContainsValue
1 parent f761cdb commit 9007e29

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

util_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package websocket
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
)
11+
12+
var tokenListContainsValueTests = []struct {
13+
value string
14+
ok bool
15+
}{
16+
{"WebSocket", true},
17+
{"WEBSOCKET", true},
18+
{"websocket", true},
19+
{"websockets", false},
20+
{"x websocket", false},
21+
{"websocket x", false},
22+
{"other,websocket,more", true},
23+
{"other, websocket, more", true},
24+
}
25+
26+
func TestTokenListContainsValue(t *testing.T) {
27+
for _, tt := range tokenListContainsValueTests {
28+
h := http.Header{"Upgrade": {tt.value}}
29+
ok := tokenListContainsValue(h, "Upgrade", "websocket")
30+
if ok != tt.ok {
31+
t.Errorf("tokenListContainsValue(h, n, %q) = %v, want %v", tt.value, ok, tt.ok)
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)