apitester

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TeeReadCloser

func TeeReadCloser(r io.ReadCloser, w io.Writer) io.ReadCloser

Types

type APITester

type APITester struct {
	TestLogger *testutils.TestLogger
	Logger     zerolog.Logger
	DB         *database.TestDB

	Config restapi.APIConfig
	// contains filtered or unexported fields
}

APITester provides facilities to unittest the RednerD rest api.

func NewAPITester

func NewAPITester(
	ctx context.Context,
	t *testing.T,
	engineOptions *cmd.EngineOptions,
	serverOptions ...ServerOption,
) *APITester

NewAPITester setup a APITester. false positive on thelper that I can't figure out. it should allow t *testing.T param to be second here but weirdly does not.

func (*APITester) APITest

func (tester *APITester) APITest(name ...string) *apitest.APITest

func (*APITester) Close

func (tester *APITester) Close()

Close releases all underlying resources. MUST be called, preferably with defer.

func (*APITester) CreateTemplate

func (tester *APITester) CreateTemplate(
	username string,
	body, response *models.Template,
)

CreateTemplate creates a new template associated to an Account.

func (*APITester) CreateUser

func (tester *APITester) CreateUser(username, password string)

CreateUser creates a new user and sets its password.

func (*APITester) Debug

func (tester *APITester) Debug()

Debug() method checks the debug boolean. used to put Debug() on apitester calls, to see more informations.

func (*APITester) Do

func (tester *APITester) Do(req *http.Request) (*http.Response, error)

func (*APITester) DoJSONRequest

func (tester *APITester) DoJSONRequest(verb, url string, body interface{}, response interface{}) (int, error)

DoJSONRequest creates and run request.

func (*APITester) DoJSONRequestCtx

func (tester *APITester) DoJSONRequestCtx(
	ctx context.Context,
	verb, url string,
	body, response interface{},
) (int, error)

DoJSONRequestCtx creates and run request. Needs a context.

func (*APITester) DoRequest

func (tester *APITester) DoRequest(verb, url, body string) (int, string, error)

DoRequest creates and run request.

func (*APITester) DoRequestCtx

func (tester *APITester) DoRequestCtx(ctx context.Context, verb, url, body string) (int, string, error)

DoRequestCtx creates and run request. Needs a context.

func (*APITester) DoWithPayload

func (tester *APITester) DoWithPayload(verb, url string)

DoWithPayload creates and run request that takes a payload.

func (*APITester) ForgotPassword

func (tester *APITester) ForgotPassword(body *auth.ForgotPasswordBody)

ForgotPassword sends an email to the user to reset his password.

func (*APITester) Get

func (tester *APITester) Get(url string) (int, string, error)

Get runs a GET request.

func (*APITester) GetJSON

func (tester *APITester) GetJSON(url string, obj interface{}) (int, error)

GetJSON runs a GET request and parse the result as JSON.

func (*APITester) GetUser

func (tester *APITester) GetUser(username string, user *models.Userinfo)

GetUser returns the uer by username.

func (*APITester) GetUserInfo

func (tester *APITester) GetUserInfo() models.Userinfo

GetUserInfo returns the connected user information.

func (*APITester) HandleRequest

func (tester *APITester) HandleRequest(req *http.Request) *httptest.ResponseRecorder

HandleRequest pass a request through the handler.

func (*APITester) ListEngines

func (tester *APITester) ListEngines() string

func (*APITester) ListUsers

func (tester *APITester) ListUsers(users *[]*models.Userinfo)

ListUsers returns all the users.

func (*APITester) Login

func (tester *APITester) Login(username, password string)

Login authenticates the user for the subsequent requests.

func (*APITester) Logout

func (tester *APITester) Logout()

Logout resets the "Authorization" headers.

func (*APITester) MustDoJSONRequest

func (tester *APITester) MustDoJSONRequest(verb, url string, body interface{}, response interface{}) int

MustDoJSONRequest creates and run request that takes no payload.

func (*APITester) MustDoJSONRequestCtx

func (tester *APITester) MustDoJSONRequestCtx(
	ctx context.Context,
	verb, url string,
	body, response interface{},
) int

MustDoJSONRequestCtx creates and run request that takes no payload. Needs a context.

func (*APITester) MustDoRequest

func (tester *APITester) MustDoRequest(verb, url, body string) (int, string)

MustDoRequest ...

func (*APITester) MustGet

func (tester *APITester) MustGet(url string) (int, string)

MustGet runs a GET request an panics if it fails.

func (*APITester) MustGetJSON

func (tester *APITester) MustGetJSON(url string, obj interface{}) int

MustGetJSON runs a GET request, parse the result as JSON and panic on any error.

func (*APITester) MustGetJSONCtx

func (tester *APITester) MustGetJSONCtx(ctx context.Context, url string, obj interface{}) int

MustGetJSONCtx runs a GET request, parse the result as JSON and panic on any error. Needs a context.

func (*APITester) MustPost

func (tester *APITester) MustPost(url string, body string) (int, string)

MustPost runs a POST request and panic if it fails.

func (*APITester) MustPostJSON

func (tester *APITester) MustPostJSON(
	url string,
	body, response interface{},
) int

MustPostJSON is like PostJSON but stops the test on failure.

func (*APITester) MustPostJSONCtx

func (tester *APITester) MustPostJSONCtx(
	ctx context.Context,
	url string,
	body, response interface{},
) int

MustPostJSONCtx is like PostJSON but stops the test on failure. Needs a context.

func (*APITester) MustPut

func (tester *APITester) MustPut(url string, body string) (int, string)

MustPut runs a POST request and panic if it fails.

func (*APITester) MustPutJSON

func (tester *APITester) MustPutJSON(url string, body interface{}, response interface{}) int

MustPutJSON is like PutJSON but stops the test on failure.

func (*APITester) Now

func (tester *APITester) Now() time.Time

Gets the APITester current time.

func (*APITester) Post

func (tester *APITester) Post(url string, body string) (int, string, error)

Post runs a POST request.

func (*APITester) PostJSON

func (tester *APITester) PostJSON(url string, body interface{}, response interface{}) (int, error)

PostJSON runs a POST request with given input marshalled as JSON and responsed unmarshalled from JSON.

func (*APITester) Put

func (tester *APITester) Put(url string, body string) (int, string, error)

Put runs a POST request.

func (*APITester) PutJSON

func (tester *APITester) PutJSON(url string, body interface{}, response interface{}) (int, error)

PutJSON runs a POST request with given input marshalled as JSON and responsed unmarshalled from JSON.

func (*APITester) Register

func (tester *APITester) Register(reg *models.Registration)

Register registers the user to the API.

func (*APITester) Render

func (tester *APITester) Render(
	data *models.RenderRequest,
	result *[]*models.Document,
)

Render renders some data and returns a document.

func (*APITester) RenderLogs

func (tester *APITester) RenderLogs(
	period string,
) string

Renderlogs gives us a csv document containing the Rendering data for invoicing.

func (*APITester) ResetNow

func (tester *APITester) ResetNow()

Resets the APITester current time.

func (*APITester) ResetPassword

func (tester *APITester) ResetPassword(body *auth.ResetPasswordBody)

ResetPassword reset the password.

func (*APITester) Run

func (tester *APITester) Run(name string, run func(t *testing.T)) bool

Run runs the test as t.Run would, and call SetTB in addition.

func (*APITester) ServeHTTP

func (tester *APITester) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*APITester) SetHeader

func (tester *APITester) SetHeader(key, value string)

SetHeader sets a header for all subsequent requests.

func (*APITester) SetNow

func (tester *APITester) SetNow(t time.Time)

sets the tester current time to another value. Warning: the API now does not change with this method. Only way of changing the API time is to recreate an APITester.

func (*APITester) SetPassword

func (tester *APITester) SetPassword(username, password string)

SetPassword sets the user's password.

func (*APITester) SetT

func (tester *APITester) SetT(t *testing.T) func()

SetT switch the current t and returns a func that restore the initial one.

func (*APITester) UpdateTemplate

func (tester *APITester) UpdateTemplate(
	username, templateName string,
	body, response *models.Template,
)

UpdateTemplate updates an existing template associated to an Account.

func (*APITester) Varlist

func (tester *APITester) Varlist(tmpl *models.Template) []string

Varlist gives us the variables inside a template..

type JSONObj

type JSONObj map[string]interface{}

JSONObj is a map.

type ServerOption

type ServerOption func(*restapi.Server)

Jump to

Keyboard shortcuts

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