forked from bitly/oauth2_proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket_test.go
47 lines (42 loc) · 1015 Bytes
/
websocket_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"net/http"
"testing"
"github.com/bmizerany/assert"
)
func TestCopyHeader(t *testing.T) {
src := http.Header{
"EmptyValue": []string{""},
"Nil": []string{},
"Single": []string{"one"},
"Multi": []string{"one", "two"},
}
expected := http.Header{
"Single": []string{"one"},
"Multi": []string{"one", "two"},
}
dst := http.Header{}
for key, _ := range src {
copyHeader(&dst, src, key)
}
assert.Equal(t, expected, dst)
}
func TestUpgrade(t *testing.T) {
tests := []struct {
upgrade bool
connectionValue string
upgradeValue string
}{
{true, "Upgrade", "Websocket"},
{true, "keepalive, Upgrade", "websocket"},
{false, "", "websocket"},
{false, "keepalive, Upgrade", ""},
}
for _, tt := range tests {
req := new(http.Request)
req.Header = http.Header{}
req.Header.Set(ConnectionHeaderKey, tt.connectionValue)
req.Header.Set(UpgradeHeaderKey, tt.upgradeValue)
assert.Equal(t, tt.upgrade, isWebsocketRequest(req))
}
}