func (t *Tester) Update(tt *testing.T, model, response, result coal.Model) Result {
	res, doc, err := t.DataClient.Update(model)
	assert.NoError(tt, err)
	if err == nil && response != nil {
		assert.Equal(tt, response, res)
	}
	if err == nil && result != nil {
		actual := coal.GetMeta(model).Make()
		t.Tester.Fetch(actual, model.ID())
		assert.Equal(tt, result, actual)
	}
	return Result{
		Model:    res,
		Document: doc,
		Error:    err,
	}
}
Update will update the provided model and validate the response and result
if requested.
package roast
import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"
	"github.com/256dpi/fire"
	"github.com/256dpi/fire/coal"
	"github.com/256dpi/jsonapi/v2"
	"github.com/256dpi/oauth2/v2"
	"github.com/256dpi/serve"
	"github.com/256dpi/xo"
	"github.com/stretchr/testify/assert"
)
var AccessDenied = fire.ErrAccessDenied.Self().(*xo.Err).Err
var ResourceNotFound = fire.ErrResourceNotFound.Self().(*xo.Err).Err
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
}
type Result struct {
	Error    error
	Model    coal.Model
	Models   []coal.Model
	Document *jsonapi.Document
}
type Tester struct {
	*fire.Tester
	RawClient  *http.Client
	DataClient *Client
	AuthClient *oauth2.Client
	AuthToken  string
}
func NewTester(config Config) *Tester {
	tester := &Tester{
		Tester: fire.NewTester(config.Store, config.Models...),
	}
	tester.Prefix = config.DataNamespace
	tester.Tester.Handler = config.Handler
	tester.RawClient = &http.Client{
		Transport: serve.Local(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if config.Debug {
				fmt.Println(r.Method, r.URL.String())
			}
			tester.Tester.Handler.ServeHTTP(w, r)
			if config.Debug {
				rec := w.(*httptest.ResponseRecorder)
				fmt.Println(rec.Code, rec.Body.String())
			}
		})),
	}
	if config.Authorizer == nil {
		config.Authorizer = func(req *http.Request) {
			if tester.AuthToken != "" {
				req.Header.Set("Authorization", "Bearer "+tester.AuthToken)
			}
		}
	}
	tester.DataClient = NewClient(jsonapi.NewClientWithClient(jsonapi.ClientConfig{
		BaseURI:       "/" + strings.Trim(config.DataNamespace, "/"),
		Authorizer:    config.Authorizer,
		ResponseLimit: serve.MustByteSize("8M"),
	}, tester.RawClient))
	tester.AuthClient = oauth2.NewClientWithClient(oauth2.ClientConfig{
		BaseURI:       "/" + strings.Trim(config.AuthNamespace, "/"),
		TokenEndpoint: "/" + strings.Trim(config.TokenEndpoint, "/"),
	}, tester.RawClient)
	return tester
}
func (t *Tester) Authenticate(clientID, username, password string, scope ...string) {
	res, err := t.AuthClient.Authenticate(oauth2.TokenRequest{
		GrantType: oauth2.PasswordGrantType,
		Scope:     scope,
		ClientID:  clientID,
		Username:  username,
		Password:  password,
	})
	if err != nil {
		panic(err)
	}
	t.AuthToken = res.AccessToken
}
func (t *Tester) Invalidate() {
	t.AuthToken = ""
}
func (t *Tester) List(tt *testing.T, model coal.Model, response []coal.Model) Result {
	res, doc, err := t.DataClient.List(model)
	assert.NoError(tt, err)
	if err == nil && response != nil {
		assert.Equal(tt, response, res)
	}
	return Result{
		Models:   res,
		Document: doc,
		Error:    err,
	}
}
func (t *Tester) ListError(tt *testing.T, model coal.Model, e error) Result {
	_, doc, err := t.DataClient.List(model)
	assert.Error(tt, err)
	if e != nil {
		assert.Equal(tt, e, err)
	}
	return Result{
		Document: doc,
		Error:    err,
	}
}
func (t *Tester) Find(tt *testing.T, model coal.Model, response coal.Model) Result {
	res, doc, err := t.DataClient.Find(model)
	assert.NoError(tt, err)
	if err == nil && response != nil {
		assert.Equal(tt, response, res)
	}
	return Result{
		Model:    res,
		Document: doc,
		Error:    err,
	}
}
func (t *Tester) FindError(tt *testing.T, model coal.Model, e error) Result {
	_, doc, err := t.DataClient.Find(model)
	assert.Error(tt, err)
	if e != nil {
		assert.Equal(tt, e, err)
	}
	return Result{
		Document: doc,
		Error:    err,
	}
}
func (t *Tester) Create(tt *testing.T, model, response, result coal.Model) Result {
	res, doc, err := t.DataClient.Create(model)
	assert.NoError(tt, err)
	if err == nil && response != nil {
		response.GetBase().DocID = res.ID()
		assert.Equal(tt, response, res)
	}
	if err == nil && result != nil {
		result.GetBase().DocID = res.ID()
		actual := coal.GetMeta(model).Make()
		t.Tester.Fetch(actual, res.ID())
		assert.Equal(tt, result, actual)
	}
	return Result{
		Model:    res,
		Document: doc,
		Error:    err,
	}
}
func (t *Tester) CreateError(tt *testing.T, model coal.Model, e error) Result {
	_, doc, err := t.DataClient.Create(model)
	assert.Error(tt, err)
	if e != nil {
		assert.Equal(tt, e, err)
	}
	return Result{
		Document: doc,
		Error:    err,
	}
}