server_test.go 845 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2013 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. package websocket
  5. import (
  6. "net/http"
  7. "reflect"
  8. "testing"
  9. )
  10. var subprotocolTests = []struct {
  11. h string
  12. protocols []string
  13. }{
  14. {"", nil},
  15. {"foo", []string{"foo"}},
  16. {"foo,bar", []string{"foo", "bar"}},
  17. {"foo, bar", []string{"foo", "bar"}},
  18. {" foo, bar", []string{"foo", "bar"}},
  19. {" foo, bar ", []string{"foo", "bar"}},
  20. }
  21. func TestSubprotocols(t *testing.T) {
  22. for _, st := range subprotocolTests {
  23. r := http.Request{Header: http.Header{"Sec-Websocket-Protocol": {st.h}}}
  24. protocols := Subprotocols(&r)
  25. if !reflect.DeepEqual(st.protocols, protocols) {
  26. t.Errorf("SubProtocols(%q) returned %#v, want %#v", st.h, protocols, st.protocols)
  27. }
  28. }
  29. }