Skip to content

Commit

Permalink
removed testify dependency in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igm committed Nov 18, 2019
1 parent 2e3acba commit 6b28a2b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
22 changes: 16 additions & 6 deletions sockjs/handler_test.go
Expand Up @@ -8,8 +8,6 @@ import (
"net/url"
"testing"
"time"

"github.com/stretchr/testify/require"
)

var testOptions = DefaultOptions
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
44 changes: 33 additions & 11 deletions sockjs/websocket_test.go
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/gorilla/websocket"
"github.com/stretchr/testify/require"
)

func TestHandler_WebSocketHandshakeError(t *testing.T) {
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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")
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6b28a2b

Please sign in to comment.