-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:The-K-R-O-K/flow-go into illia-ma…
…lachyn/6635-tests-for-websocket-controller
- Loading branch information
Showing
13 changed files
with
905 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
package websockets | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gorilla/websocket" | ||
) | ||
|
||
// We wrap gorilla's websocket connection with interface | ||
// to be able to mock it in order to test the types dependent on it | ||
|
||
type WebsocketConnection interface { | ||
ReadJSON(v interface{}) error | ||
WriteJSON(v interface{}) error | ||
WriteControl(messageType int, deadline time.Time) error | ||
Close() error | ||
SetReadDeadline(deadline time.Time) error | ||
SetWriteDeadline(deadline time.Time) error | ||
SetPongHandler(h func(string) error) | ||
} | ||
|
||
type GorillaWebsocketConnection struct { | ||
type WebsocketConnectionImpl struct { | ||
conn *websocket.Conn | ||
} | ||
|
||
func NewGorillaWebsocketConnection(conn *websocket.Conn) *GorillaWebsocketConnection { | ||
return &GorillaWebsocketConnection{ | ||
func NewWebsocketConnection(conn *websocket.Conn) *WebsocketConnectionImpl { | ||
return &WebsocketConnectionImpl{ | ||
conn: conn, | ||
} | ||
} | ||
|
||
var _ WebsocketConnection = (*GorillaWebsocketConnection)(nil) | ||
var _ WebsocketConnection = (*WebsocketConnectionImpl)(nil) | ||
|
||
func (c *WebsocketConnectionImpl) ReadJSON(v interface{}) error { | ||
return c.conn.ReadJSON(v) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) WriteJSON(v interface{}) error { | ||
return c.conn.WriteJSON(v) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) WriteControl(messageType int, deadline time.Time) error { | ||
return c.conn.WriteControl(messageType, nil, deadline) | ||
} | ||
|
||
func (m *GorillaWebsocketConnection) ReadJSON(v interface{}) error { | ||
return m.conn.ReadJSON(v) | ||
func (c *WebsocketConnectionImpl) Close() error { | ||
return c.conn.Close() | ||
} | ||
|
||
func (m *GorillaWebsocketConnection) WriteJSON(v interface{}) error { | ||
return m.conn.WriteJSON(v) | ||
func (c *WebsocketConnectionImpl) SetReadDeadline(deadline time.Time) error { | ||
return c.conn.SetReadDeadline(deadline) | ||
} | ||
|
||
func (m *GorillaWebsocketConnection) SetCloseHandler(handler func(code int, text string) error) { | ||
m.conn.SetCloseHandler(handler) | ||
func (c *WebsocketConnectionImpl) SetWriteDeadline(deadline time.Time) error { | ||
return c.conn.SetWriteDeadline(deadline) | ||
} | ||
|
||
func (m *GorillaWebsocketConnection) Close() error { | ||
return m.conn.Close() | ||
func (c *WebsocketConnectionImpl) SetPongHandler(h func(string) error) { | ||
c.conn.SetPongHandler(h) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.