roast

package
v0.34.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessDenied = fire.ErrAccessDenied.Self()

AccessDenied is the raw access denied error value.

View Source
var DocumentNotUnique = fire.ErrDocumentNotUnique.Self()

DocumentNotUnique is thr raw document not unique error value.

View Source
var Ignore = any(ignore{})

Ignore may be returned by generate to ignore an item.

View Source
var ResourceNotFound = fire.ErrResourceNotFound.Self()

ResourceNotFound is the raw resource not found error value.

Functions

func CopyHook added in v0.34.4

func CopyHook(fields ...string) func(res, cmp coal.Model)

CopyHook will copy fields from the response to the result.

func N

func N() int64

N will return a unique number.

func Now

func Now() time.Time

Now returns the time in UTC and second precision to ensure encoding/decoding stability.

func S

func S(str string) string

S will replace all # with a unique number and return the string.

func SkipHook added in v0.34.4

func SkipHook(fields ...string) func(res, cmp coal.Model)

SkipHook will copy fields from the result to the response.

func T

func T(t string) time.Time

T will return a timestamp for a time like "Jul 16 16:16:16".

Types

type Config

type Config struct {
	Tester           *fire.Tester
	Store            *coal.Store  // ignored, if Tester is provided
	Models           []coal.Model // ignored, if Tester is provided
	Handler          http.Handler
	DataNamespace    string
	AuthNamespace    string
	TokenEndpoint    string
	UploadEndpoint   string
	DownloadEndpoint string
	Authorizer       func(req *http.Request)
	Debug            bool
}

Config provides configuration of a tester.

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory is model factory for tests.

func NewFactory

func NewFactory(tester *coal.Tester) *Factory

NewFactory creates and returns a new factory.

func (*Factory) Insert

func (f *Factory) Insert(model coal.Model, others ...coal.Model) coal.Model

Insert make and insert a new model with the provided models merged into the registered base model.

func (*Factory) Make

func (f *Factory) Make(model coal.Model, others ...coal.Model) coal.Model

Make will make and return a new model with the provided models merged into the registered base model.

func (*Factory) Register

func (f *Factory) Register(fns ...func() coal.Model)

Register will register the provided model factories.

type Item added in v0.33.0

type Item map[string]any

Item is single combination of dimensions.

func (Item) Is added in v0.33.0

func (i Item) Is(name string, value any) bool

Is will check if the specified dimension value matches.

func (Item) Match added in v0.33.0

func (i Item) Match(queries ...Query) bool

Match will return whether the item matches one of provided queries.

type Matrix added in v0.33.0

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix provides a facility for matrix testing.

func NewMatrix added in v0.33.0

func NewMatrix() *Matrix

NewMatrix returns a new matrix.

func (*Matrix) Bool added in v0.33.0

func (m *Matrix) Bool(name string)

Bool will generate a boolean dimension.

func (*Matrix) Generate added in v0.33.0

func (m *Matrix) Generate(name string, values []any, fn func(value any, item Item) any)

Generate will generate a dimension using the specified values and generator. The generator may be absent to just add the provided values. If the generator returns Ignore the value will be skipped.

func (*Matrix) Items added in v0.33.0

func (m *Matrix) Items(name string, queries ...Query) []Item

Items will return a dimension's items that match at least on of the specified queries. If no queries are specified the full list is returned. Queries are parsed using the Common Expression Language (CEL).

func (*Matrix) Values added in v0.33.0

func (m *Matrix) Values(name string, values ...any)

Values will generate a dimension using the specified values.

type Query added in v0.33.0

type Query func(Item) bool

Query represents an item query.

type Result

type Result struct {
	Error    error
	Model    coal.Model
	Models   []coal.Model
	Document *jsonapi.Document
}

Result is returned by the tester.

type Tester

type Tester struct {
	*fire.Tester
	Config     Config
	RawClient  *http.Client
	DataClient *fire.Client
	AuthClient *oauth2.Client
	AuthToken  string
}

Tester provides a high-level unit test facility.

func NewTester

func NewTester(config Config) *Tester

NewTester will create and return a new tester.

func (*Tester) Authenticate

func (t *Tester) Authenticate(clientID, username, password string, scope ...string)

Authenticate will request an access token using the provided credentials.

func (*Tester) Await added in v0.33.1

func (t *Tester) Await(tt *testing.T, timeout time.Duration, fns ...func()) int

Await will wait for all jobs created during the execution of the callback to complete. A timeout may be provided to stop after some time.

func (*Tester) Call added in v0.33.1

func (t *Tester) Call(tt *testing.T, url string, in, out any) (int, *jsonapi.Error)

Call will call a JSON based action with the provided input and output at the specified URL. If out is absent, the function will try to decode and return any jsonapi.Error.

func (*Tester) Create

func (t *Tester) Create(tt *testing.T, model, response, result coal.Model, hooks ...func(res, cmp coal.Model)) Result

Create will create the provided model and validate the response and result if requested.

func (*Tester) CreateError

func (t *Tester) CreateError(tt *testing.T, model coal.Model, expected error) Result

CreateError will create the provided model and expect and error.

func (*Tester) Delete

func (t *Tester) Delete(tt *testing.T, model, result coal.Model, hooks ...func(res, cmp coal.Model)) Result

Delete will delete the provided model and validate the result.

func (*Tester) DeleteError

func (t *Tester) DeleteError(tt *testing.T, model coal.Model, expected error) Result

DeleteError will delete the provided model and expect an error.

func (*Tester) Download added in v0.33.0

func (t *Tester) Download(tt *testing.T, key string, typ, name string, data []byte) []byte

Download will download data using the specified view key. It will verify the files media type, name and data if requested.

func (*Tester) Find

func (t *Tester) Find(tt *testing.T, model coal.Model, response coal.Model, hooks ...func(res, cmp coal.Model)) Result

Find will find the provided model and validate the response if requested.

func (*Tester) FindError

func (t *Tester) FindError(tt *testing.T, model coal.Model, expected error) Result

FindError will find the provided model and expect and error.

func (*Tester) Invalidate

func (t *Tester) Invalidate()

Invalidate will clear the current authentication.

func (*Tester) List

func (t *Tester) List(tt *testing.T, model coal.Model, response []coal.Model, hooks ...func(res, cmp coal.Model)) Result

List will list the provided model and validate the response if requested.

func (*Tester) ListError

func (t *Tester) ListError(tt *testing.T, model coal.Model, expected error) Result

ListError will list the provided model and expect an error.

func (*Tester) URL added in v0.33.1

func (t *Tester) URL(path ...string) string

URL returns a URL based on the specified path segments.

func (*Tester) Update

func (t *Tester) Update(tt *testing.T, model, response, result coal.Model, hooks ...func(res, cmp coal.Model)) Result

Update will update the provided model and validate the response and result if requested.

func (*Tester) UpdateError

func (t *Tester) UpdateError(tt *testing.T, model coal.Model, expected error) Result

UpdateError will update the provided model and expect an error.

func (*Tester) Upload added in v0.33.0

func (t *Tester) Upload(tt *testing.T, data []byte, typ, name string) string

Upload will upload the specified data with the provided media type and name.

Jump to

Keyboard shortcuts

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