ablytest

package
v0.0.0-...-e3c37a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ClientOptionsInspector struct {
	UseBinaryProtocol func([]ably.ClientOption) bool
	HTTPClient        func([]ably.ClientOption) *http.Client
}
View Source
var DefaultLogLevel = ably.LogNone
View Source
var DiscardLogger ably.Logger = discardLogger{}
View Source
var Environment = "sandbox"
View Source
var Instantly = Before(10 * time.Millisecond)
View Source
var NoBinaryProtocol bool
View Source
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"}`},
	}
}
View Source
var Soon = Before(Timeout)
View Source
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 Contains

func Contains(s, sub interface{}) bool

func FullRealtimeCloser

func FullRealtimeCloser(c *ably.Realtime) io.Closer

FullRealtimeCloser returns an io.Closer that, on Close, calls Close on the Realtime instance and waits for its effects.

func GetReconnectionTimersFrom

func GetReconnectionTimersFrom(t *testing.T, afterCalls <-chan AfterCall) (reconnect AfterCall, suspend AfterCall)

func ItemsEqual

func ItemsEqual(expected, got []interface{}, equal func(x, y interface{}) bool) bool

func MergeOptions

func MergeOptions(opts ...[]ably.ClientOption) []ably.ClientOption

func MustQuery

func MustQuery(req *http.Request) url.Values

func NewHTTPClient

func NewHTTPClient() *http.Client

func NewHTTPClientNoKeepAlive

func NewHTTPClientNoKeepAlive() *http.Client

func NewLogger

func NewLogger(messages chan<- LogMessage) ably.Logger

func NewTokenParams

func NewTokenParams(query url.Values) *ably.TokenParams

func Query

func Query(req *http.Request) (url.Values, error)

func ReceiveMessages

func ReceiveMessages(channel *ably.RealtimeChannel, name string) (messages <-chan *ably.Message, unsubscribe func(), err error)

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.

func Wait

func Wait(res Result, err error) error

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) Fire

func (c AfterCall) Fire()

func (AfterCall) IsTriggered

func (a AfterCall) IsTriggered() bool

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 Channel

type Channel struct {
	Name     string     `json:"name"`
	Presence []Presence `json:"presence,omitempty"`
}

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 Connection struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

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{})

A FmtFunc is a non-failing function analogous to fmt.Printf.

func (FmtFunc) Wrap

func (f FmtFunc) Wrap(t *testing.T, format string, args ...interface{}) FmtFunc

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-test-utilities/ablytest"
)

func main() {
	println := ablytest.FmtFunc(func(format string, args ...interface{}) {
		fmt.Println(fmt.Sprintf(format, args...))
	})

	id := 42
	wrapped := println.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 LogMessage struct {
	Level   ably.LogLevel
	Message string
}

type MessageChannel

type MessageChannel chan *ably.Message

func (MessageChannel) Receive

func (ch MessageChannel) Receive(m *ably.Message)

type Namespace

type Namespace struct {
	ID        string `json:"id"`
	Created   int    `json:"created,omitempty"`
	Modified  int    `json:"modified,omitempty"`
	Persisted bool   `json:"persisted,omitempty"`
}

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 Presence

type Presence struct {
	ClientID string `json:"clientId"`
	Data     string `json:"data"`
	Encoding string `json:"encoding,omitempty"`
}

type PresenceChannel

type PresenceChannel chan *ably.PresenceMessage

func (PresenceChannel) Receive

func (ch PresenceChannel) Receive(m *ably.PresenceMessage)

type Result

type Result interface {
	Wait(context.Context) error
}

func AssertionWaiter

func AssertionWaiter(assertion func() bool) Result

func ConnWaiter

func ConnWaiter(client *ably.Realtime, do func(), expectedEvent ...ably.ConnectionEvent) Result

type ResultFunc

type ResultFunc func(context.Context) error

func (ResultFunc) Go

func (f ResultFunc) Go() Result

func (ResultFunc) Wait

func (f ResultFunc) Wait(ctx context.Context) error

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

type RoundTripRecorder struct {
	*http.Transport
	// contains filtered or unexported fields
}

RoundTripRecorder is a http.Transport wrapper which records HTTP request/response pairs.

func (*RoundTripRecorder) Hijack

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) RoundTrip

func (rec *RoundTripRecorder) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface.

func (*RoundTripRecorder) Stop

func (rec *RoundTripRecorder) Stop()

Stop makes the recorder stop recording new requests/responses.

type Sandbox

type Sandbox struct {
	Config      *Config
	Environment string
	// contains filtered or unexported fields
}

func MustSandbox

func MustSandbox(config *Config) *Sandbox

func NewREST

func NewREST(opts ...ably.ClientOption) (*Sandbox, *ably.REST)

func NewRealtime

func NewRealtime(opts ...ably.ClientOption) (*Sandbox, *ably.Realtime)

func NewSandbox

func NewSandbox(config *Config) (*Sandbox, error)

func NewSandboxWIthEnv

func NewSandboxWIthEnv(config *Config, env string) (*Sandbox, error)

func (*Sandbox) Close

func (app *Sandbox) Close() error

func (*Sandbox) Key

func (app *Sandbox) Key() string

func (*Sandbox) KeyParts

func (app *Sandbox) KeyParts() (name, secret string)

func (*Sandbox) NewRealtime

func (app *Sandbox) NewRealtime(opts ...ably.ClientOption) *ably.Realtime

func (*Sandbox) Options

func (app *Sandbox) Options(opts ...ably.ClientOption) []ably.ClientOption

func (*Sandbox) URL

func (app *Sandbox) URL(paths ...string) string

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.

func (WithTimeout) Send

func (wt WithTimeout) Send(t *testing.T, ch, v interface{}, fail func(fmt string, args ...interface{}), failExtraArgs ...interface{}) (ok bool)

Send is like Recv, except it sends.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL