Documentation
¶
Index ¶
- Variables
- func AllPages(dst, paginatedRequest interface{}) error
- func Contains(s, sub interface{}) bool
- func FullRealtimeCloser(c *ably.Realtime) io.Closer
- func GetReconnectionTimersFrom(t *testing.T, afterCalls <-chan AfterCall) (reconnect AfterCall, suspend AfterCall)
- func ItemsEqual(expected, got []interface{}, equal func(x, y interface{}) bool) bool
- func MergeOptions(opts ...[]ably.ClientOption) []ably.ClientOption
- func MustQuery(req *http.Request) url.Values
- func NewHTTPClient() *http.Client
- func NewHTTPClientNoKeepAlive() *http.Client
- func NewLogger(messages chan<- LogMessage) ably.Logger
- func NewTokenParams(query url.Values) *ably.TokenParams
- func Query(req *http.Request) (url.Values, error)
- func ReceiveMessages(channel *ably.RealtimeChannel, name string) (messages <-chan *ably.Message, unsubscribe func(), err error)
- func ReceivePresenceMessages(channel *ably.RealtimeChannel, action *ably.PresenceAction) (messages <-chan *ably.PresenceMessage, unsubscribe func(), err error)
- func TestPagination(expected, request interface{}, perPage int, options ...PaginationOption) error
- func TimeFuncs(afterCalls chan<- AfterCall) (now func() time.Time, ...)
- func Wait(res Result, err error) error
- type AfterCall
- type AuthReverseProxy
- func (srv *AuthReverseProxy) Callback(responseType string) func(context.Context, ably.TokenParams) (ably.Tokener, error)
- func (srv *AuthReverseProxy) Close() error
- func (srv *AuthReverseProxy) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (srv *AuthReverseProxy) URL(responseType string) string
- type ChanStatesRecorder
- type Channel
- type Config
- type ConnErrorsRecorder
- type ConnStatesRecorder
- type Connection
- type CryptoData
- type FmtFunc
- type Key
- type LogMessage
- type MessageChannel
- type Namespace
- type PaginationOption
- type Presence
- type PresenceChannel
- type Result
- type ResultFunc
- type ResultGroup
- type RoundTripRecorder
- func (rec *RoundTripRecorder) Hijack(rt http.RoundTripper) http.RoundTripper
- func (rec *RoundTripRecorder) Len() int
- func (rec *RoundTripRecorder) Request(n int) *http.Request
- func (rec *RoundTripRecorder) Requests() []*http.Request
- func (rec *RoundTripRecorder) Reset()
- func (rec *RoundTripRecorder) Response(n int) *http.Response
- func (rec *RoundTripRecorder) Responses() []*http.Response
- func (rec *RoundTripRecorder) RoundTrip(req *http.Request) (*http.Response, error)
- func (rec *RoundTripRecorder) Stop()
- type Sandbox
- func MustSandbox(config *Config) *Sandbox
- func NewREST(opts ...ably.ClientOption) (*Sandbox, *ably.REST)
- func NewRealtime(opts ...ably.ClientOption) (*Sandbox, *ably.Realtime)
- func NewSandbox(config *Config) (*Sandbox, error)
- func NewSandboxWithEndpoint(config *Config, endpoint string) (*Sandbox, error)
- func (app *Sandbox) Close() error
- func (app *Sandbox) CreateJwt(expiresIn time.Duration, invalid bool) (string, error)
- func (app *Sandbox) GetJwtAuthParams(expiresIn time.Duration, invalid bool) url.Values
- func (app *Sandbox) Key() string
- func (app *Sandbox) KeyParts() (name, secret string)
- func (app *Sandbox) NewRealtime(opts ...ably.ClientOption) *ably.Realtime
- func (app *Sandbox) Options(opts ...ably.ClientOption) []ably.ClientOption
- func (app *Sandbox) URL(paths ...string) string
- type WithTimeout
- func (wt WithTimeout) IsTrue(pred func() bool) bool
- func (wt WithTimeout) NoRecv(t *testing.T, into, from interface{}, ...) (ok bool)
- func (wt WithTimeout) Recv(t *testing.T, into, from interface{}, ...) (ok bool)
- func (wt WithTimeout) Send(t *testing.T, ch, v interface{}, fail func(fmt string, args ...interface{}), ...) (ok bool)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var CREATE_JWT_URL string = "https://echo.ably.io/createJWT"
Source code for the same => https://github.com/ably/echoserver/blob/main/app.js
var ClientOptionsInspector struct { UseBinaryProtocol func([]ably.ClientOption) bool HTTPClient func([]ably.ClientOption) *http.Client }
var DefaultLogLevel = ably.LogNone
var DiscardLogger ably.Logger = discardLogger{}
var Endpoint = "nonprod:sandbox"
var Instantly = Before(10 * time.Millisecond)
var NoBinaryProtocol bool
var PresenceFixtures = func() []Presence { return []Presence{ {ClientID: "client_bool", Data: "true"}, {ClientID: "client_int", Data: "true"}, {ClientID: "client_string", Data: "true"}, {ClientID: "client_json", Data: `{"test": "This is a JSONObject clientData payload"}`}, } }
var Soon = Before(Timeout)
var Timeout = 30 * time.Second
Functions ¶
func AllPages ¶
func AllPages(dst, paginatedRequest interface{}) error
AllPages appends all items from all pages resulting from a paginated request into the slice pointed to by dst, which must be a pointer to a slice of the same type as the paginated response's items.
func FullRealtimeCloser ¶
FullRealtimeCloser returns an io.Closer that, on Close, calls Close on the Realtime instance and waits for its effects.
func ItemsEqual ¶
func MergeOptions ¶
func MergeOptions(opts ...[]ably.ClientOption) []ably.ClientOption
func NewHTTPClient ¶
func NewLogger ¶
func NewLogger(messages chan<- LogMessage) ably.Logger
func NewTokenParams ¶
func NewTokenParams(query url.Values) *ably.TokenParams
func ReceiveMessages ¶
func ReceivePresenceMessages ¶
func ReceivePresenceMessages(channel *ably.RealtimeChannel, action *ably.PresenceAction) (messages <-chan *ably.PresenceMessage, unsubscribe func(), err error)
func TestPagination ¶
func TestPagination(expected, request interface{}, perPage int, options ...PaginationOption) error
TestPagination takes a PaginatedRequest and the unwrapped expected items its resulting pages should contain, and tests that the pages do contain those items, plus some generic PaginatedResponse functionality, such as Pages and Items methods, and the First method.
func TimeFuncs ¶
func TimeFuncs(afterCalls chan<- AfterCall) ( now func() time.Time, after func(context.Context, time.Duration) <-chan time.Time, )
TimeFuncs returns time functions to be passed as options.
Now returns a stable time that is only updated with the times that the returned After produces.
After forwards calls to the given channel. The receiver is in charge of sending the resulting time to the AfterCall.Time channel.
Types ¶
type AfterCall ¶
type AfterCall struct { Ctx context.Context D time.Duration Deadline time.Time Time chan<- time.Time // contains filtered or unexported fields }
func (AfterCall) IsTriggered ¶
type AuthReverseProxy ¶
type AuthReverseProxy struct { TokenQueue []*ably.TokenDetails // when non-nil pops the token from the queue instead querying Ably servers Listener net.Listener // listener which accepts token request connections // contains filtered or unexported fields }
AuthReverseProxy serves token requests by reverse proxying them to the Ably servers. Use URL method for creating values for AuthURL option and Callback method - for AuthCallback ones.
func MustAuthReverseProxy ¶
func MustAuthReverseProxy(opts ...ably.ClientOption) *AuthReverseProxy
MustAuthReverseProxy panics when creating the proxy fails.
func NewAuthReverseProxy ¶
func NewAuthReverseProxy(opts ...ably.ClientOption) (*AuthReverseProxy, error)
NewAuthReverseProxy creates new auth reverse proxy. The given opts are used to create a Auth client, used to reverse proxying token requests.
func (*AuthReverseProxy) Callback ¶
func (srv *AuthReverseProxy) Callback(responseType string) func(context.Context, ably.TokenParams) (ably.Tokener, error)
Callback gives new AuthCallback. Available response types are the same as for URL method.
func (*AuthReverseProxy) Close ¶
func (srv *AuthReverseProxy) Close() error
Close makes the proxy server stop accepting connections.
func (*AuthReverseProxy) ServeHTTP ¶
func (srv *AuthReverseProxy) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface.
func (*AuthReverseProxy) URL ¶
func (srv *AuthReverseProxy) URL(responseType string) string
URL gives new AuthURL for the requested responseType. Available response types are:
- "token", which responds with (ably.TokenDetails).Token as a string
- "details", which responds with ably.TokenDetails
- "request", which responds with ably.TokenRequest
type ChanStatesRecorder ¶
type ChanStatesRecorder struct {
// contains filtered or unexported fields
}
func (*ChanStatesRecorder) Listen ¶
func (cs *ChanStatesRecorder) Listen(channel *ably.RealtimeChannel) (off func())
func (*ChanStatesRecorder) States ¶
func (cs *ChanStatesRecorder) States() []ably.ChannelState
type Config ¶
type Config struct { ID string `json:"id,omitempty"` AppID string `json:"appId,omitempty"` AccountID string `json:"accountId,omitempty"` Status int `json:"status,omitempty"` Created int `json:"created,omitempty"` Modified int `json:"modified,omitempty"` TLSOnly bool `json:"tlsOnly,omitempty"` Labels string `json:"labels,omitempty"` Keys []Key `json:"keys"` Namespaces []Namespace `json:"namespaces"` Channels []Channel `json:"channels"` Connections []Connection `json:"connections,omitempty"` }
func DefaultConfig ¶
func DefaultConfig() *Config
type ConnErrorsRecorder ¶
type ConnErrorsRecorder struct {
// contains filtered or unexported fields
}
func (*ConnErrorsRecorder) Errors ¶
func (ce *ConnErrorsRecorder) Errors() []*ably.ErrorInfo
func (*ConnErrorsRecorder) Listen ¶
func (ce *ConnErrorsRecorder) Listen(r *ably.Realtime) (off func())
type ConnStatesRecorder ¶
type ConnStatesRecorder struct {
// contains filtered or unexported fields
}
func (*ConnStatesRecorder) Listen ¶
func (cs *ConnStatesRecorder) Listen(r *ably.Realtime) (off func())
func (*ConnStatesRecorder) States ¶
func (cs *ConnStatesRecorder) States() []ably.ConnectionState
type Connection ¶
type CryptoData ¶
type CryptoData struct { Algorithm string `json:"algorithm"` Mode string `json:"mode"` KeyLen int `json:"keylength"` Key string `json:"key"` IV string `json:"iv"` Items []struct { Encoded json.RawMessage `json:"encoded"` Encrypted json.RawMessage `json:"encrypted"` } `json:"items"` }
func LoadCryptoData ¶
func LoadCryptoData(rel string) (*CryptoData, []byte, []byte, error)
type FmtFunc ¶
type FmtFunc func(format string, args ...interface{})
FmtFunc is a non-failing function analogous to fmt.Printf.
func (FmtFunc) Wrap ¶
Wrap wraps a FmtFunc in another. The wrapper FmtFunc first uses the fixed format and args, plus the format it's called with, to create a new format string by calling fmt.Sprintf. Then, it calls the wrapped FmtFunc with this format string and the args the wrapper is called with.
It's useful to have some fixed context on everything that is formatted with a FmtFunc, e.g. test scope context.
Example ¶
package main import ( "fmt" "github.com/ably/ably-go/ablytest" ) func main() { myPrintln := ablytest.FmtFunc(func(format string, args ...interface{}) { fmt.Println(fmt.Sprintf(format, args...)) }) id := 42 wrapped := myPrintln.Wrap(nil, "for ID %d: %s", id) wrapped("everything's OK") errMsg := "all hell broke loose" wrapped("something failed: %s", errMsg) }
Output: for ID 42: everything's OK for ID 42: something failed: all hell broke loose
type Key ¶
type Key struct { ID string `json:"id,omitempty"` ScopeID string `json:"scopeId,omitempty"` Status int `json:"status,omitempty"` Type int `json:"type,omitempty"` Value string `json:"value,omitempty"` Created int `json:"created,omitempty"` Modified int `json:"modified,omitempty"` Capability string `json:"capability,omitempty"` Expires int `json:"expired,omitempty"` Privileged bool `json:"privileged,omitempty"` }
type LogMessage ¶
type MessageChannel ¶
func (MessageChannel) Receive ¶
func (ch MessageChannel) Receive(m *ably.Message)
type PaginationOption ¶
type PaginationOption func(*paginationOptions)
func PaginationWithEqual ¶
func PaginationWithEqual(equal func(x, y interface{}) bool) PaginationOption
func PaginationWithSortResult ¶
func PaginationWithSortResult(sort func([]interface{})) PaginationOption
type PresenceChannel ¶
type PresenceChannel chan *ably.PresenceMessage
func (PresenceChannel) Receive ¶
func (ch PresenceChannel) Receive(m *ably.PresenceMessage)
type Result ¶
func AssertionWaiter ¶
func ConnWaiter ¶
func ConnWaiter(client *ably.Realtime, do func(), expectedEvent ...ably.ConnectionEvent) Result
type ResultFunc ¶
func (ResultFunc) Go ¶
func (f ResultFunc) Go() Result
type ResultGroup ¶
type ResultGroup struct {
// contains filtered or unexported fields
}
ResultGroup is like sync.WaitGroup, but for Result values.
ResultGroup blocks till last added Result has completed successfully.
If at least Result value failed, ResultGroup returns first encountered error immediately.
func (*ResultGroup) Add ¶
func (rg *ResultGroup) Add(res Result, err error)
func (*ResultGroup) GoAdd ¶
func (rg *ResultGroup) GoAdd(f ResultFunc)
func (*ResultGroup) Wait ¶
func (rg *ResultGroup) Wait() error
type RoundTripRecorder ¶
RoundTripRecorder is a http.Transport wrapper which records HTTP request/response pairs.
func NewHttpRecorder ¶ added in v1.2.20
func NewHttpRecorder() (*RoundTripRecorder, []ably.ClientOption)
func (*RoundTripRecorder) Hijack ¶
func (rec *RoundTripRecorder) Hijack(rt http.RoundTripper) http.RoundTripper
Hijack injects http.Transport into the wrapper.
func (*RoundTripRecorder) Len ¶
func (rec *RoundTripRecorder) Len() int
Len gives number of recorded request/response pairs.
It is save to call Len() before calling Stop().
func (*RoundTripRecorder) Request ¶
func (rec *RoundTripRecorder) Request(n int) *http.Request
Request gives nth recorded http.Request.
func (*RoundTripRecorder) Requests ¶
func (rec *RoundTripRecorder) Requests() []*http.Request
Requests gives all HTTP requests in order they were recorded.
func (*RoundTripRecorder) Reset ¶
func (rec *RoundTripRecorder) Reset()
Reset resets the recorder requests and responses.
func (*RoundTripRecorder) Response ¶
func (rec *RoundTripRecorder) Response(n int) *http.Response
Response gives nth recorded http.Response.
func (*RoundTripRecorder) Responses ¶
func (rec *RoundTripRecorder) Responses() []*http.Response
Responses gives all HTTP responses in order they were recorded.
func (*RoundTripRecorder) Stop ¶
func (rec *RoundTripRecorder) Stop()
Stop makes the recorder stop recording new requests/responses.
type Sandbox ¶
func MustSandbox ¶
func NewRealtime ¶
func NewRealtime(opts ...ably.ClientOption) (*Sandbox, *ably.Realtime)
func NewSandbox ¶
func NewSandboxWithEndpoint ¶ added in v1.2.22
func (*Sandbox) CreateJwt ¶ added in v1.2.21
CreateJwt generates a JWT with the specified expiration time.
Parameters: - expiresIn: The duration until the JWT expires. - invalid: A boolean flag indicating whether to use an invalid key secret.
Returns: - A string containing the generated JWT. - An error if the JWT creation fails.
func (*Sandbox) GetJwtAuthParams ¶ added in v1.2.21
GetJwtAuthParams constructs the authentication parameters required for JWT creation. Required when authUrl is chosen as a mode of auth
Parameters: - expiresIn: The duration until the JWT expires. - invalid: A boolean flag indicating whether to use an invalid key secret.
Returns: A url.Values object containing the authentication parameters.
func (*Sandbox) NewRealtime ¶
func (app *Sandbox) NewRealtime(opts ...ably.ClientOption) *ably.Realtime
func (*Sandbox) Options ¶
func (app *Sandbox) Options(opts ...ably.ClientOption) []ably.ClientOption
type WithTimeout ¶
type WithTimeout struct {
// contains filtered or unexported fields
}
WithTimeout configures test helpers with a timeout.
func Before ¶
func Before(d time.Duration) WithTimeout
Before returns a WithTimeout with the given timeout duration.
func (WithTimeout) IsTrue ¶
func (wt WithTimeout) IsTrue(pred func() bool) bool
func (WithTimeout) NoRecv ¶
func (wt WithTimeout) NoRecv(t *testing.T, into, from interface{}, fail func(fmt string, args ...interface{}), failExtraArgs ...interface{}) (ok bool)
NoRecv is like Recv, except it asserts no value is received.
func (WithTimeout) Recv ¶
func (wt WithTimeout) Recv(t *testing.T, into, from interface{}, fail func(fmt string, args ...interface{}), failExtraArgs ...interface{}) (ok bool)
Recv asserts that a value is received through channel from before the timeout. If it isn't, the fail function is called.
If into is non-nil, it must be a pointer to a variable of the same type as from's element type and it will be set to the received value, if any.
It returns the second, boolean value returned by the receive operation, or false if the operation times out.