github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/gorilla/websocket/util_test.go (about)

     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  }