Documentation
¶
Overview ¶
Package jawstest provides an importable harness for driving a jaws.Request's WebSocket message-processing loop in tests.
It lives in its own package, rather than in package jaws, so that net/http/httptest stays out of the production build of consumers that import github.com/linkdata/jaws. It reaches the request loop through the exported jaws.Jaws.TestServe hook.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestRequest ¶
type TestRequest struct {
*jaws.Request
Recorder *httptest.ResponseRecorder
ReadyCh chan struct{}
DoneCh chan struct{}
InCh chan wire.WsMsg
OutCh chan wire.WsMsg
BcastCh chan wire.Message
}
TestRequest is a request harness intended for tests.
The embedded jaws.Request provides the usual request methods (NewElement, JawsKeyString, and so on). The channels expose the loop's wiring: send incoming WebSocket messages on InCh, read outbound messages from OutCh, and inject broadcasts on BcastCh. ReadyCh is closed once the loop is running and DoneCh once it has stopped.
func NewTestRequest ¶
func NewTestRequest(jw *jaws.Jaws, r *http.Request) *TestRequest
NewTestRequest creates a TestRequest for use when testing. Passing nil for r creates a GET / request with no body. It requires the Jaws processing loop (jaws.Jaws.Serve or jaws.Jaws.ServeWithTimeout) to be running, and returns nil if the request cannot be created or claimed.
func (*TestRequest) BodyHTML ¶
func (tr *TestRequest) BodyHTML() template.HTML
BodyHTML returns the recorded response body as trusted HTML.
func (*TestRequest) BodyString ¶
func (tr *TestRequest) BodyString() string
BodyString returns the recorded response body with surrounding whitespace removed.
func (*TestRequest) Close ¶
func (tr *TestRequest) Close()
Close stops the test request's processing loop.