Documentation
¶
Index ¶
- func AssertPanic(t Testing, cb func())
- func AssertResponseBody(t *testing.T, r io.Reader, body interface{})
- func AssertResponseContainsMetrics(t *testing.T, r *http.Response, metrics []string)
- func AssertResponseHeaders(t *testing.T, r *http.Response, h map[string]string)
- func AssertResponseMultiHeaders(t *testing.T, r *http.Response, h map[string][]string)
- func AssertResponseStatusCode(t *testing.T, r *http.Response, code int)
- func DefaultConfig(cfgs ...func(*server.Config)) server.Config
- func SplitAtLastSpace(s string) (string, string)
- type ClientEvent
- func (ev *ClientEvent) AssertData(t *testing.T, data interface{}) *ClientEvent
- func (ev *ClientEvent) AssertEventName(t *testing.T, event string) *ClientEvent
- func (ev *ClientEvent) Equals(t *testing.T, event string, data interface{}) *ClientEvent
- func (ev *ClientEvent) IsData(data interface{}) bool
- type ClientRequest
- type ClientResponse
- func (cr *ClientResponse) AssertError(t *testing.T, err *reserr.Error) *ClientResponse
- func (cr *ClientResponse) AssertErrorCode(t *testing.T, code string) *ClientResponse
- func (cr *ClientResponse) AssertIsError(t *testing.T) *ClientResponse
- func (cr *ClientResponse) AssertResult(t *testing.T, result interface{}) *ClientResponse
- type Conn
- func (c *Conn) AssertClosed(t *testing.T)
- func (c *Conn) AssertNoEvent(t *testing.T, rid string)
- func (c *Conn) AssertNoNATSRequest(t *testing.T, rid string)
- func (c *Conn) Disconnect()
- func (c *Conn) Error() error
- func (c *Conn) GetEvent(t *testing.T) *ClientEvent
- func (c *Conn) GetParallelEvents(t *testing.T, n int) ParallelEvents
- func (c *Conn) PanicOnError()
- func (c *Conn) Request(method string, params interface{}) *ClientRequest
- type CountLogger
- func (l *CountLogger) AssertErrorsLogged(t *testing.T, count int)
- func (l *CountLogger) AssertNoErrorsLogged(t *testing.T)
- func (l *CountLogger) Debug(s string)
- func (l *CountLogger) Error(s string)
- func (l *CountLogger) IsDebug() bool
- func (l *CountLogger) IsTrace() bool
- func (l *CountLogger) Log(s string)
- func (l *CountLogger) String() string
- func (l *CountLogger) Trace(s string)
- type HTTPRequest
- type HTTPResponse
- func (hr *HTTPResponse) AssertBody(t *testing.T, body interface{}) *HTTPResponse
- func (hr *HTTPResponse) AssertError(t *testing.T, err *reserr.Error) *HTTPResponse
- func (hr *HTTPResponse) AssertErrorCode(t *testing.T, code string) *HTTPResponse
- func (hr *HTTPResponse) AssertHeaders(t *testing.T, h map[string]string) *HTTPResponse
- func (hr *HTTPResponse) AssertIsError(t *testing.T) *HTTPResponse
- func (hr *HTTPResponse) AssertMissingHeaders(t *testing.T, h []string) *HTTPResponse
- func (hr *HTTPResponse) AssertMultiHeaders(t *testing.T, h map[string][]string) *HTTPResponse
- func (hr *HTTPResponse) AssertStatusCode(t *testing.T, code int) *HTTPResponse
- func (hr *HTTPResponse) Equals(t *testing.T, code int, body interface{}) *HTTPResponse
- type LogTesting
- type NATSTestClient
- func (c *NATSTestClient) Close()
- func (c *NATSTestClient) ConnEvent(cid string, event string, payload interface{})
- func (c *NATSTestClient) Connect() error
- func (c *NATSTestClient) Debugf(format string, v ...interface{})
- func (c *NATSTestClient) Errorf(format string, v ...interface{})
- func (c *NATSTestClient) GetParallelRequests(t Testing, n int) ParallelRequests
- func (c *NATSTestClient) GetRequest(t Testing) *Request
- func (c *NATSTestClient) HasSubscriptions(t Testing, rids ...string)
- func (c *NATSTestClient) IsClosed() bool
- func (c *NATSTestClient) Logf(format string, v ...interface{})
- func (c *NATSTestClient) NoSubscriptions(t Testing, rids ...string)
- func (c *NATSTestClient) ResourceEvent(rid string, event string, payload interface{})
- func (c *NATSTestClient) SendRequest(subj string, payload []byte, cb mq.Response)
- func (c *NATSTestClient) SetClosedHandler(_ func(error))
- func (c *NATSTestClient) Subscribe(namespace string, cb mq.Response) (mq.Unsubscriber, error)
- func (c *NATSTestClient) SystemEvent(event string, payload interface{})
- func (c *NATSTestClient) Tracef(format string, v ...interface{})
- type ParallelEvents
- type ParallelRequests
- type Request
- func (r *Request) AssertNotPathPayload(t Testing, path string, payload interface{}) *Request
- func (r *Request) AssertPathMissing(t Testing, path string) *Request
- func (r *Request) AssertPathPayload(t Testing, path string, payload interface{}) *Request
- func (r *Request) AssertPathType(t Testing, path string, typ interface{}) *Request
- func (r *Request) AssertPayload(t Testing, payload interface{}) *Request
- func (r *Request) AssertSubject(t Testing, subject string) *Request
- func (r *Request) Equals(t Testing, subject string, payload interface{}) *Request
- func (r *Request) PathPayload(t Testing, path string) interface{}
- func (r *Request) Respond(data interface{})
- func (r *Request) RespondError(err *reserr.Error)
- func (r *Request) RespondRaw(out []byte)
- func (r *Request) RespondResource(rid string)
- func (r *Request) RespondSuccess(result interface{})
- func (r *Request) SendError(err error)
- func (r *Request) Timeout()
- func (r *Request) TryPathPayload(t Testing, path string) (interface{}, bool)
- type Session
- func (s *Session) AssertUnsubscribe(rids ...string) *Session
- func (s *Session) AwaitUnsubscribe() string
- func (s *Session) Connect() *Conn
- func (s *Session) ConnectWithChannel(evs chan *ClientEvent) *Conn
- func (s *Session) ConnectWithHeader(h http.Header) *Conn
- func (s *Session) ConnectWithResponse() (*Conn, *http.Response, error)
- func (s *Session) ConnectWithVersion(version string) *Conn
- func (s *Session) ConnectWithoutVersion() *Conn
- func (s *Session) HTTPRequest(method, url string, body []byte, opts ...func(r *http.Request)) *HTTPRequest
- func (s *Session) IsBadHandshake(err error) bool
- func (s *Session) MetricsHTTPRequest(opts ...func(r *http.Request)) *http.Response
- type Subscription
- type Testing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertPanic ¶ added in v1.5.0
func AssertPanic(t Testing, cb func())
AssertPanic expects the callback function to panic, otherwise logs an error with t.Errorf
func AssertResponseBody ¶ added in v1.8.0
AssertResponseBody asserts that the response has the expected body
func AssertResponseContainsMetrics ¶ added in v1.8.0
AssertResponseContainsMetrics asserts that the body of the response contains the metric values.
func AssertResponseHeaders ¶ added in v1.8.0
AssertResponseHeaders asserts that the response includes the expected headers
func AssertResponseMultiHeaders ¶ added in v1.8.0
AssertResponseMultiHeaders asserts that the response includes the expected headers, including repeated headers such as Set-Cookie.
func AssertResponseStatusCode ¶ added in v1.8.0
AssertResponseStatusCode asserts that the response has the expected status code
func DefaultConfig ¶ added in v1.5.0
DefaultConfig returns a default server configuration used for testing
func SplitAtLastSpace ¶ added in v1.8.0
SplitAtLastSpace splits a string at the last space found.
Types ¶
type ClientEvent ¶
type ClientEvent struct { Event string Data interface{} }
ClientEvent represents a RES-client event sent to the client
func (*ClientEvent) AssertData ¶
func (ev *ClientEvent) AssertData(t *testing.T, data interface{}) *ClientEvent
AssertData asserts that the event has the expected data
func (*ClientEvent) AssertEventName ¶
func (ev *ClientEvent) AssertEventName(t *testing.T, event string) *ClientEvent
AssertEventName asserts that the event has the expected event name
func (*ClientEvent) Equals ¶
func (ev *ClientEvent) Equals(t *testing.T, event string, data interface{}) *ClientEvent
Equals asserts that the event has the expected event name and payload
func (*ClientEvent) IsData ¶ added in v1.7.0
func (ev *ClientEvent) IsData(data interface{}) bool
IsData checks if the data matches, and returns true if it does, otherwise false.
type ClientRequest ¶
type ClientRequest struct { Method string Params interface{} // contains filtered or unexported fields }
ClientRequest represents a RES-client request
func (*ClientRequest) GetResponse ¶
func (cr *ClientRequest) GetResponse(t *testing.T) *ClientResponse
GetResponse awaits for a response and returns it. Fails if a response hasn't arrived within 1 second.
type ClientResponse ¶
ClientResponse represents a response to a RES-client request
func (*ClientResponse) AssertError ¶
func (cr *ClientResponse) AssertError(t *testing.T, err *reserr.Error) *ClientResponse
AssertError asserts that the response has the expected error
func (*ClientResponse) AssertErrorCode ¶
func (cr *ClientResponse) AssertErrorCode(t *testing.T, code string) *ClientResponse
AssertErrorCode asserts that the response has the expected error code
func (*ClientResponse) AssertIsError ¶ added in v1.2.2
func (cr *ClientResponse) AssertIsError(t *testing.T) *ClientResponse
AssertIsError asserts that the response is an error
func (*ClientResponse) AssertResult ¶
func (cr *ClientResponse) AssertResult(t *testing.T, result interface{}) *ClientResponse
AssertResult asserts that the response has the expected result
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a client websocket connection
func (*Conn) AssertClosed ¶ added in v1.1.0
AssertClosed asserts that the connection is closed
func (*Conn) AssertNoEvent ¶
AssertNoEvent assert that no events are queued
func (*Conn) AssertNoNATSRequest ¶
AssertNoNATSRequest assert that no request are queued on NATS
func (*Conn) Disconnect ¶
func (c *Conn) Disconnect()
Disconnect closes the connection to the gateway
func (*Conn) GetEvent ¶
func (c *Conn) GetEvent(t *testing.T) *ClientEvent
GetEvent gets a pending event that is sent to the client. If no event is received within a set amount of time, it will log it as a fatal error.
func (*Conn) GetParallelEvents ¶
func (c *Conn) GetParallelEvents(t *testing.T, n int) ParallelEvents
GetParallelEvents gets n number of events where the order is uncertain.
func (*Conn) PanicOnError ¶ added in v1.2.1
func (c *Conn) PanicOnError()
PanicOnError panics if the connection has encountered an error.
func (*Conn) Request ¶
func (c *Conn) Request(method string, params interface{}) *ClientRequest
Request sends a properly formatted request to the gateway using the method and parameters provided.
type CountLogger ¶ added in v1.4.0
type CountLogger struct {
// contains filtered or unexported fields
}
CountLogger writes log messages to os.Stderr
func NewCountLogger ¶ added in v1.4.0
func NewCountLogger(debug bool, trace bool) *CountLogger
NewCountLogger returns a new logger that writes to a bytes buffer
func (*CountLogger) AssertErrorsLogged ¶ added in v1.4.0
func (l *CountLogger) AssertErrorsLogged(t *testing.T, count int)
AssertErrorsLogged asserts that some error has been logged and clears the error count
func (*CountLogger) AssertNoErrorsLogged ¶ added in v1.4.0
func (l *CountLogger) AssertNoErrorsLogged(t *testing.T)
AssertNoErrorsLogged asserts that no error has been logged
func (*CountLogger) Debug ¶ added in v1.4.0
func (l *CountLogger) Debug(s string)
Debug writes a debug entry
func (*CountLogger) Error ¶ added in v1.4.0
func (l *CountLogger) Error(s string)
Error writes an error entry
func (*CountLogger) IsDebug ¶ added in v1.4.0
func (l *CountLogger) IsDebug() bool
IsDebug returns true if debug logging is active
func (*CountLogger) IsTrace ¶ added in v1.4.0
func (l *CountLogger) IsTrace() bool
IsTrace returns true if trace logging is active
func (*CountLogger) Log ¶ added in v1.4.0
func (l *CountLogger) Log(s string)
Log writes a log entry
func (*CountLogger) String ¶ added in v1.4.0
func (l *CountLogger) String() string
String returns the log
func (*CountLogger) Trace ¶ added in v1.4.0
func (l *CountLogger) Trace(s string)
Trace writes a trace entry
type HTTPRequest ¶
type HTTPRequest struct {
// contains filtered or unexported fields
}
HTTPRequest represents a HTTP requests made to the gateway
func (*HTTPRequest) GetResponse ¶
func (hr *HTTPRequest) GetResponse(t *testing.T) *HTTPResponse
GetResponse awaits for a response and returns it. Fails if a response hasn't arrived within 1 second.
type HTTPResponse ¶
type HTTPResponse struct {
*httptest.ResponseRecorder
}
HTTPResponse represents a response received from a HTTP request made to the gateway
func (*HTTPResponse) AssertBody ¶
func (hr *HTTPResponse) AssertBody(t *testing.T, body interface{}) *HTTPResponse
AssertBody asserts that the response has the expected body
func (*HTTPResponse) AssertError ¶
func (hr *HTTPResponse) AssertError(t *testing.T, err *reserr.Error) *HTTPResponse
AssertError asserts that the response does not have status 200, and has the expected error
func (*HTTPResponse) AssertErrorCode ¶
func (hr *HTTPResponse) AssertErrorCode(t *testing.T, code string) *HTTPResponse
AssertErrorCode asserts that the response does not have status 200, and has the expected error code
func (*HTTPResponse) AssertHeaders ¶
func (hr *HTTPResponse) AssertHeaders(t *testing.T, h map[string]string) *HTTPResponse
AssertHeaders asserts that the response includes the expected headers
func (*HTTPResponse) AssertIsError ¶ added in v1.2.2
func (hr *HTTPResponse) AssertIsError(t *testing.T) *HTTPResponse
AssertIsError asserts that the response does not have status 200, and that the body has an error code.
func (*HTTPResponse) AssertMissingHeaders ¶ added in v1.5.0
func (hr *HTTPResponse) AssertMissingHeaders(t *testing.T, h []string) *HTTPResponse
AssertMissingHeaders asserts that the response does not include the given headers
func (*HTTPResponse) AssertMultiHeaders ¶ added in v1.8.0
func (hr *HTTPResponse) AssertMultiHeaders(t *testing.T, h map[string][]string) *HTTPResponse
AssertMultiHeaders asserts that the response includes the expected headers, including repeated headers such as Set-Cookie.
func (*HTTPResponse) AssertStatusCode ¶
func (hr *HTTPResponse) AssertStatusCode(t *testing.T, code int) *HTTPResponse
AssertStatusCode asserts that the response has the expected status code
func (*HTTPResponse) Equals ¶
func (hr *HTTPResponse) Equals(t *testing.T, code int, body interface{}) *HTTPResponse
Equals asserts that the response has the expected status code and body
type LogTesting ¶ added in v1.8.0
type LogTesting struct { // If true, does not panic when Fatal or Fatalf is called. NoPanic bool Err error }
func (*LogTesting) Defer ¶ added in v1.8.0
func (t *LogTesting) Defer()
func (*LogTesting) Error ¶ added in v1.8.0
func (t *LogTesting) Error(args ...interface{})
func (*LogTesting) Errorf ¶ added in v1.8.0
func (t *LogTesting) Errorf(format string, args ...interface{})
func (*LogTesting) Fatal ¶ added in v1.8.0
func (t *LogTesting) Fatal(args ...interface{})
func (*LogTesting) Fatalf ¶ added in v1.8.0
func (t *LogTesting) Fatalf(format string, args ...interface{})
type NATSTestClient ¶
type NATSTestClient struct {
// contains filtered or unexported fields
}
NATSTestClient holds a client connection to a nats server.
func NewNATSTestClient ¶
func NewNATSTestClient(l logger.Logger) *NATSTestClient
NewNATSTestClient creates a new NATSTestClient instance
func (*NATSTestClient) ConnEvent ¶
func (c *NATSTestClient) ConnEvent(cid string, event string, payload interface{})
ConnEvent sends a connection event to resgate. The subject will be "conn."+cid+"."+event . It panics if there is no subscription for such event.
func (*NATSTestClient) Connect ¶
func (c *NATSTestClient) Connect() error
Connect establishes a connection to the MQ
func (*NATSTestClient) Debugf ¶
func (c *NATSTestClient) Debugf(format string, v ...interface{})
Debugf writes a formatted debug message
func (*NATSTestClient) Errorf ¶ added in v1.4.0
func (c *NATSTestClient) Errorf(format string, v ...interface{})
Errorf writes a formatted error message
func (*NATSTestClient) GetParallelRequests ¶
func (c *NATSTestClient) GetParallelRequests(t Testing, n int) ParallelRequests
GetParallelRequests gets n number of requests where the order is uncertain.
func (*NATSTestClient) GetRequest ¶
func (c *NATSTestClient) GetRequest(t Testing) *Request
GetRequest gets a pending request that is sent to NATS. If no request is received within a set amount of time, it will log it as a fatal error.
func (*NATSTestClient) HasSubscriptions ¶
func (c *NATSTestClient) HasSubscriptions(t Testing, rids ...string)
HasSubscriptions asserts that there is a subscription for the given resource IDs
func (*NATSTestClient) IsClosed ¶
func (c *NATSTestClient) IsClosed() bool
IsClosed tests if the client connection has been closed.
func (*NATSTestClient) Logf ¶
func (c *NATSTestClient) Logf(format string, v ...interface{})
Logf writes a formatted log message
func (*NATSTestClient) NoSubscriptions ¶ added in v1.6.0
func (c *NATSTestClient) NoSubscriptions(t Testing, rids ...string)
NoSubscriptions asserts that there isn't any subscription for the given resource IDs.
func (*NATSTestClient) ResourceEvent ¶
func (c *NATSTestClient) ResourceEvent(rid string, event string, payload interface{})
ResourceEvent sends a resource event to resgate. The subject will be "event."+rid+"."+event . It panics if there is no subscription for such event.
func (*NATSTestClient) SendRequest ¶
func (c *NATSTestClient) SendRequest(subj string, payload []byte, cb mq.Response)
SendRequest sends an asynchronous request on a subject, expecting the Response callback to be called once.
func (*NATSTestClient) SetClosedHandler ¶
func (c *NATSTestClient) SetClosedHandler(_ func(error))
SetClosedHandler sets the handler when the connection is closed
func (*NATSTestClient) Subscribe ¶
func (c *NATSTestClient) Subscribe(namespace string, cb mq.Response) (mq.Unsubscriber, error)
Subscribe to all events on a resource namespace. The namespace has the format "event."+resource
func (*NATSTestClient) SystemEvent ¶
func (c *NATSTestClient) SystemEvent(event string, payload interface{})
SystemEvent sends a system event to resgate. The subject will be "system."+event . It panics if there is no subscription for such event.
func (*NATSTestClient) Tracef ¶
func (c *NATSTestClient) Tracef(format string, v ...interface{})
Tracef writes a formatted trace message
type ParallelEvents ¶
type ParallelEvents []*ClientEvent
ParallelEvents holds multiple events in undetermined order
func (ParallelEvents) GetEvent ¶
func (pr ParallelEvents) GetEvent(t *testing.T, event string) *ClientEvent
GetEvent returns a event based on event name.
type ParallelRequests ¶
type ParallelRequests []*Request
ParallelRequests holds multiple requests in undetermined order
func (ParallelRequests) GetRequest ¶
func (pr ParallelRequests) GetRequest(t Testing, subject string) *Request
GetRequest returns a request based on subject.
type Request ¶
type Request struct { Subject string RawPayload []byte Payload interface{} // contains filtered or unexported fields }
Request represent a request to NATS
func (*Request) AssertNotPathPayload ¶ added in v1.8.0
AssertNotPathPayload asserts that the request payload at a given dot-separated path in a nested object does not have the provided payload or is missing.
func (*Request) AssertPathMissing ¶ added in v1.8.0
AssertPathMissing asserts that the request payload at a given dot-separated path in a nested object is missing. It gives a fatal error if any other part of the patch except for the last part of the path is missing.
func (*Request) AssertPathPayload ¶
AssertPathPayload asserts that a the request payload at a given dot-separated path in a nested object has the expected payload.
func (*Request) AssertPathType ¶
AssertPathType asserts that a the request payload at a given dot-separated path in a nested object has the same type as typ.
func (*Request) AssertPayload ¶
AssertPayload asserts that the request has the expected payload
func (*Request) AssertSubject ¶
AssertSubject asserts that the request has the expected subject
func (*Request) PathPayload ¶
PathPayload returns the request payload at a given dot-separated path in a nested object. It gives a fatal error if the path doesn't exist.
func (*Request) Respond ¶
func (r *Request) Respond(data interface{})
Respond sends a low level response
func (*Request) RespondError ¶
RespondError sends an error response
func (*Request) RespondRaw ¶
RespondRaw sends a raw byte response
func (*Request) RespondResource ¶ added in v1.4.0
RespondResource sends a resource response
func (*Request) RespondSuccess ¶
func (r *Request) RespondSuccess(result interface{})
RespondSuccess sends a success response
func (*Request) TryPathPayload ¶ added in v1.8.0
TryPathPayload returns the request payload at a given dot-separated path in a nested object, and true, if it exist. Otherwise it returns nil and false. It gives a fatal error if any other part of the patch except for the last part of the path is missing. It gives a fatal error if the path doesn't exist.
type Session ¶
type Session struct { *NATSTestClient *CountLogger // contains filtered or unexported fields }
Session represents a test session with a resgate server
func (*Session) AssertUnsubscribe ¶ added in v1.8.0
AssertUnsubscribe awaits for one or more resources to be unsubscribed by the cache, and asserts that they match the provided resource IDs.
func (*Session) AwaitUnsubscribe ¶ added in v1.8.0
AwaitUnsubscribe awaits for a resource to be unsubscribed by the cache, returning the resource ID.
func (*Session) Connect ¶
Connect makes a new mock client websocket connection that handshakes with version v1.999.999.
func (*Session) ConnectWithChannel ¶ added in v1.1.0
func (s *Session) ConnectWithChannel(evs chan *ClientEvent) *Conn
ConnectWithChannel makes a new mock client websocket connection with a ClientEvent channel.
func (*Session) ConnectWithHeader ¶ added in v1.5.0
ConnectWithHeader makes a new mock client websocket connection using provided headers. It does not send a version handshake.
func (*Session) ConnectWithResponse ¶ added in v1.8.0
ConnectWithResponse makes a new mock client websocket connection that handshakes with version v1.999.999, if a connection is established. If an error occurs, it returns the error without handshake.
func (*Session) ConnectWithVersion ¶ added in v1.6.0
ConnectWithVersion makes a new mock client websocket connection that handshakes with the version string provided.
func (*Session) ConnectWithoutVersion ¶ added in v1.4.0
ConnectWithoutVersion makes a new mock client websocket connection without any version handshake.
func (*Session) HTTPRequest ¶
func (s *Session) HTTPRequest(method, url string, body []byte, opts ...func(r *http.Request)) *HTTPRequest
HTTPRequest sends a request over HTTP
func (*Session) IsBadHandshake ¶ added in v1.8.0
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription implements the mq.Unsubscriber interface.
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe() error
Unsubscribe removes the subscription.