Skip to content

Commit

Permalink
Refactor websocket printer test
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Apr 4, 2023
1 parent 907b2e9 commit c19c388
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,38 +1047,40 @@ func TestWebsocket_Disconnect(t *testing.T) {
}
}

func TestWebsocket_PrintRead(t *testing.T) {
reporter := newMockReporter(t)
printer := &mockWebsocketPrinter{}
config := Config{
Reporter: reporter,
Printers: []Printer{printer},
}.withDefaults()
ws := newWebsocket(newMockChain(t), config, &mockWebsocketConn{})

ws.printRead(websocket.CloseMessage,
[]byte("random message"),
websocket.CloseNormalClosure)

if !printer.isReadFrom {
t.Errorf("Websocket.printRead() failed to read from printer")
}
}

func TestWebsocket_PrintWrite(t *testing.T) {
reporter := newMockReporter(t)
printer := &mockWebsocketPrinter{}
config := Config{
Reporter: reporter,
Printers: []Printer{printer},
}.withDefaults()
ws := newWebsocket(newMockChain(t), config, &mockWebsocketConn{})

ws.printWrite(websocket.CloseMessage,
[]byte("random message"),
websocket.CloseNormalClosure)
func TestWebsocket_Printer(t *testing.T) {
t.Run("print read", func(t *testing.T) {
reporter := newMockReporter(t)
printer := &mockWebsocketPrinter{}
config := Config{
Reporter: reporter,
Printers: []Printer{printer},
}.withDefaults()
ws := newWebsocket(newMockChain(t), config, &mockWebsocketConn{})

ws.printRead(websocket.CloseMessage,
[]byte("random message"),
websocket.CloseNormalClosure)

if !printer.isReadFrom {
t.Errorf("Websocket.printRead() failed to read from printer")
}
})

if !printer.isWrittenTo {
t.Errorf("Websocket.printWrite() failed to write to printer")
}
t.Run("print write", func(t *testing.T) {
reporter := newMockReporter(t)
printer := &mockWebsocketPrinter{}
config := Config{
Reporter: reporter,
Printers: []Printer{printer},
}.withDefaults()
ws := newWebsocket(newMockChain(t), config, &mockWebsocketConn{})

ws.printWrite(websocket.CloseMessage,
[]byte("random message"),
websocket.CloseNormalClosure)

if !printer.isWrittenTo {
t.Errorf("Websocket.printWrite() failed to write to printer")
}
})
}

0 comments on commit c19c388

Please sign in to comment.