roast

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessDenied = fire.ErrAccessDenied.Self().(*xo.Err).Err

AccessDenied is the raw access denied error value.

View Source
var ResourceNotFound = fire.ErrResourceNotFound.Self().(*xo.Err).Err

ResourceNotFound is the raw resource not found error value.

Functions

func AssignResource

func AssignResource(model coal.Model, res *jsonapi.Resource) error

AssignResource will assign the provided resource to the specified model.

func ConvertModel

func ConvertModel(model coal.Model) (*jsonapi.Resource, error)

ConvertModel will convert the provided model to a resource.

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 T

func T(t string) time.Time

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

Types

type Client

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

Client wraps a jsonapi.Client to directly interact with models.

func NewClient

func NewClient(client *jsonapi.Client) *Client

NewClient will create and return a new client.

func (*Client) Create

func (c *Client) Create(model coal.Model) (coal.Model, *jsonapi.Document, error)

Create will create the provided model and return the created model.

func (*Client) Delete

func (c *Client) Delete(model coal.Model) error

Delete will delete the provided model.

func (*Client) Find

func (c *Client) Find(model coal.Model, reqs ...jsonapi.Request) (coal.Model, *jsonapi.Document, error)

Find will find and return the provided model.

func (*Client) List

func (c *Client) List(model coal.Model, reqs ...jsonapi.Request) ([]coal.Model, *jsonapi.Document, error)

List will list the provided models.

func (*Client) Update

func (c *Client) Update(model coal.Model) (coal.Model, *jsonapi.Document, error)

Update will update the provided model and return the updated model.

type Config

type Config struct {
	Store         *coal.Store
	Models        []coal.Model
	Handler       http.Handler
	DataNamespace string
	AuthNamespace string
	TokenEndpoint 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 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
	RawClient  *http.Client
	DataClient *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) Create

func (t *Tester) Create(tt *testing.T, model, response, result 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, e 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) Result

Delete will delete the provided model and validate the result.

func (*Tester) DeleteError

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

DeleteError will delete the provided model and expect an error.

func (*Tester) Find

func (t *Tester) Find(tt *testing.T, model coal.Model, response 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, e 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) 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, e error) Result

ListError will list the provided model and expect an error.

func (*Tester) Update

func (t *Tester) Update(tt *testing.T, model, response, result 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, e error) Result

UpdateError will updatet the provided model and expect an error.

Jump to

Keyboard shortcuts

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