util_test.go 823 B

12345678910111213141516171819202122232425262728293031323334
  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. package websocket
  5. import (
  6. "net/http"
  7. "testing"
  8. )
  9. var tokenListContainsValueTests = []struct {
  10. value string
  11. ok bool
  12. }{
  13. {"WebSocket", true},
  14. {"WEBSOCKET", true},
  15. {"websocket", true},
  16. {"websockets", false},
  17. {"x websocket", false},
  18. {"websocket x", false},
  19. {"other,websocket,more", true},
  20. {"other, websocket, more", true},
  21. }
  22. func TestTokenListContainsValue(t *testing.T) {
  23. for _, tt := range tokenListContainsValueTests {
  24. h := http.Header{"Upgrade": {tt.value}}
  25. ok := tokenListContainsValue(h, "Upgrade", "websocket")
  26. if ok != tt.ok {
  27. t.Errorf("tokenListContainsValue(h, n, %q) = %v, want %v", tt.value, ok, tt.ok)
  28. }
  29. }
  30. }