testutils

package
v0.0.0-...-4b98c26 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fatal

func Fatal(msg ...interface{})

Fatal prints a message and immediately exit the process

func NeedCouchdb

func NeedCouchdb()

NeedCouchdb kill the process if there is no couchdb running

func TODO

func TODO(t *testing.T, date string, args ...interface{})

TODO can be used as a reminder to do something in the future. The test that calls TODO will fail after the limit date, which is an efficient way to not forget about it.

Types

type CookieJar

type CookieJar struct {
	Jar *cookiejar.Jar
	URL *url.URL
}

CookieJar is a http.CookieJar which always returns all cookies. NOTE golang stdlib uses cookies for the URL (ie the testserver), not for the host (ie the instance), so we do it manually

func (*CookieJar) Cookies

func (j *CookieJar) Cookies(u *url.URL) (cookies []*http.Cookie)

Cookies implements http.CookieJar interface

func (*CookieJar) SetCookies

func (j *CookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies implements http.CookieJar interface

type TestSetup

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

TestSetup is a wrapper around a testing.M which handles setting up instance, client, VFSContext, testserver and cleaning up after itself

func NewSetup

func NewSetup(testingM *testing.M, name string) *TestSetup

NewSetup returns a new TestSetup name is used to prevent bug when tests are run in parallel

func (*TestSetup) AddCleanup

func (c *TestSetup) AddCleanup(f func() error)

AddCleanup adds a function to be run when the test is finished.

func (*TestSetup) Cleanup

func (c *TestSetup) Cleanup()

Cleanup cleanup the TestSetup

func (*TestSetup) CleanupAndDie

func (c *TestSetup) CleanupAndDie(msg ...interface{})

CleanupAndDie cleanup the TestSetup, prints a message and close the process

func (*TestSetup) GetCookieJar

func (c *TestSetup) GetCookieJar() http.CookieJar

GetCookieJar returns a cookie jar valable for test the jar discard the url passed to Cookies and SetCookies and always use the setup instance URL instead.

func (*TestSetup) GetTestClient

func (c *TestSetup) GetTestClient(scopes string) (*oauth.Client, string)

GetTestClient creates an oauth client and associated token

func (*TestSetup) GetTestInstance

func (c *TestSetup) GetTestInstance(opts ...*lifecycle.Options) *instance.Instance

GetTestInstance creates an instance with a random host The instance will be removed on container cleanup

func (*TestSetup) GetTestServer

func (c *TestSetup) GetTestServer(prefix string, routes func(*echo.Group),
	mws ...func(*echo.Echo) *echo.Echo) *httptest.Server

GetTestServer start a testServer with a single group on prefix The server will be closed on container cleanup

func (*TestSetup) GetTestServerMultipleRoutes

func (c *TestSetup) GetTestServerMultipleRoutes(mpr map[string]func(*echo.Group), mws ...func(*echo.Echo) *echo.Echo) *httptest.Server

GetTestServerMultipleRoutes starts a testServer and creates a group for each pair of (prefix, routes) given. The server will be closed on container cleanup.

func (*TestSetup) GetTmpDirectory

func (c *TestSetup) GetTmpDirectory() string

GetTmpDirectory creates a temporary directory The directory will be removed on container cleanup

func (*TestSetup) Run

func (c *TestSetup) Run() int

Run runs the underlying testing.M and cleanup

func (*TestSetup) SetupSwiftTest

func (c *TestSetup) SetupSwiftTest() error

SetupSwiftTest can be used to start an in-memory Swift server for tests.

Jump to

Keyboard shortcuts

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