diff --git a/sockjs/handler_test.go b/sockjs/handler_test.go index f7a15f9..0cd44d2 100644 --- a/sockjs/handler_test.go +++ b/sockjs/handler_test.go @@ -8,8 +8,6 @@ import ( "net/url" "testing" "time" - - "github.com/stretchr/testify/require" ) var testOptions = DefaultOptions @@ -30,8 +28,14 @@ func TestHandler_Create(t *testing.T) { defer server.Close() resp, err := http.Get(server.URL + "/echo") - require.NoError(t, err) - require.NotNil(t, resp) + if err != nil { + t.Errorf("There should not be any error, got '%s'", err) + t.FailNow() + } + if resp == nil { + t.Errorf("Response should not be nil") + t.FailNow() + } if resp.StatusCode != http.StatusOK { t.Errorf("Unexpected status code receiver, got '%d' expected '%d'", resp.StatusCode, http.StatusOK) } @@ -46,8 +50,14 @@ func TestHandler_RootPrefixInfoHandler(t *testing.T) { defer server.Close() resp, err := http.Get(server.URL + "/info") - require.NoError(t, err) - require.NotNil(t, resp) + if err != nil { + t.Errorf("There should not be any error, got '%s'", err) + t.FailNow() + } + if resp == nil { + t.Errorf("Response should not be nil") + t.FailNow() + } if resp.StatusCode != http.StatusOK { t.Errorf("Unexpected status code receiver, got '%d' expected '%d'", resp.StatusCode, http.StatusOK) diff --git a/sockjs/websocket_test.go b/sockjs/websocket_test.go index c0c68c7..af5f455 100644 --- a/sockjs/websocket_test.go +++ b/sockjs/websocket_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/stretchr/testify/require" ) func TestHandler_WebSocketHandshakeError(t *testing.T) { @@ -18,8 +17,14 @@ func TestHandler_WebSocketHandshakeError(t *testing.T) { req, _ := http.NewRequest("GET", server.URL, nil) req.Header.Set("origin", "https"+server.URL[4:]) resp, err := http.DefaultClient.Do(req) - require.NoError(t, err) - require.NotNil(t, resp) + if err != nil { + t.Errorf("There should not be any error, got '%s'", err) + t.FailNow() + } + if resp == nil { + t.Errorf("Response should not be nil") + t.FailNow() + } if resp.StatusCode != http.StatusBadRequest { t.Errorf("Unexpected response code, got '%d', expected '%d'", resp.StatusCode, http.StatusBadRequest) } @@ -33,9 +38,18 @@ func TestHandler_WebSocket(t *testing.T) { var connCh = make(chan Session) h.handlerFunc = func(conn Session) { connCh <- conn } conn, resp, err := websocket.DefaultDialer.Dial(url, nil) - require.NoError(t, err) - require.NotNil(t, conn) - require.NotNil(t, resp) + if err != nil { + t.Errorf("Unexpected error '%v'", err) + t.FailNow() + } + if conn == nil { + t.Errorf("Connection should not be nil") + t.FailNow() + } + if resp == nil { + t.Errorf("Response should not be nil") + t.FailNow() + } if resp.StatusCode != http.StatusSwitchingProtocols { t.Errorf("Wrong response code returned, got '%d', expected '%d'", resp.StatusCode, http.StatusSwitchingProtocols) } @@ -56,7 +70,14 @@ func TestHandler_WebSocketTerminationByServer(t *testing.T) { conn.Close(0, "this should be ignored") } conn, _, err := websocket.DefaultDialer.Dial(url, map[string][]string{"Origin": []string{server.URL}}) - require.NoError(t, err) + if err != nil { + t.Fatalf("websocket dial failed: %v", err) + t.FailNow() + } + if conn == nil { + t.Errorf("Connection should not be nil") + t.FailNow() + } _, msg, err := conn.ReadMessage() if string(msg) != "o" || err != nil { t.Errorf("Open frame expected, got '%s' and error '%v', expected '%s' without error", msg, err, "o") @@ -86,8 +107,11 @@ func TestHandler_WebSocketTerminationByClient(t *testing.T) { } close(done) } - conn, _, _ := websocket.DefaultDialer.Dial(url, map[string][]string{"Origin": {server.URL}}) - require.NotNil(t, conn) + conn, _, _ := websocket.DefaultDialer.Dial(url, map[string][]string{"Origin": []string{server.URL}}) + if conn == nil { + t.Errorf("Connection should not be nil") + t.FailNow() + } conn.Close() <-done } @@ -110,7 +134,6 @@ func TestHandler_WebSocketCommunication(t *testing.T) { close(done) } conn, _, _ := websocket.DefaultDialer.Dial(url, map[string][]string{"Origin": []string{server.URL}}) - require.NotNil(t, conn) conn.WriteJSON([]string{"message 3"}) var expected = []string{"o", `a["message 1"]`, `a["message 2"]`, `c[123,"close"]`} for _, exp := range expected { @@ -145,7 +168,6 @@ func TestHandler_CustomWebSocketCommunication(t *testing.T) { close(done) } conn, _, _ := websocket.DefaultDialer.Dial(url, map[string][]string{"Origin": []string{server.URL}}) - require.NotNil(t, conn) conn.WriteJSON([]string{"message 3"}) var expected = []string{"o", `a["message 1"]`, `a["message 2"]`, `c[123,"close"]`} for _, exp := range expected {