github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/igm/sockjs-go.v2/sockjs/sockjs_test.go (about)

     1  package sockjs
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httptest"
     6  	"regexp"
     7  	"testing"
     8  )
     9  
    10  func TestSockJS_ServeHTTP(t *testing.T) {
    11  	m := handler{mappings: make([]*mapping, 0)}
    12  	m.mappings = []*mapping{
    13  		&mapping{"POST", regexp.MustCompile("/foo/.*"), []http.HandlerFunc{func(http.ResponseWriter, *http.Request) {}}},
    14  	}
    15  	req, _ := http.NewRequest("GET", "/foo/bar", nil)
    16  	rec := httptest.NewRecorder()
    17  	m.ServeHTTP(rec, req)
    18  	if rec.Code != http.StatusMethodNotAllowed {
    19  		t.Errorf("Unexpected response status, got '%d' expected '%d'", rec.Code, http.StatusMethodNotAllowed)
    20  	}
    21  	req, _ = http.NewRequest("GET", "/bar", nil)
    22  	rec = httptest.NewRecorder()
    23  	m.ServeHTTP(rec, req)
    24  	if rec.Code != http.StatusNotFound {
    25  		t.Errorf("Unexpected response status, got '%d' expected '%d'", rec.Code, http.StatusNotFound)
    26  	}
    27  }