Documentation ¶
Index ¶
- func GetLog(logger logrus.FieldLogger) string
- func Must(err error)
- func RedisDeletePattern(client *redis.Client, pattern string) error
- func SetupTestDatabase(dburl string) (string, func())
- func TestLogger() logrus.FieldLogger
- func TestRegData() *url.Values
- type Message
- type SubmittableForm
- type TestClient
- func (c *TestClient) ClickLink(selector string, alter ...func(*http.Request)) *http.Response
- func (c *TestClient) CurrentUID() uuid.UUID
- func (c *TestClient) FollowRedirect(alter ...func(*http.Request)) *http.Response
- func (c *TestClient) Form(url string, alter ...func(*http.Request)) SubmittableForm
- func (c *TestClient) FormValues(formid string) *url.Values
- func (c *TestClient) RegistrationAndLogin(regdata *url.Values)
- func (c *TestClient) Request(method, target string, body io.Reader, alter ...func(*http.Request)) *http.Response
- type TestMailer
- type TestSite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLog ¶
func GetLog(logger logrus.FieldLogger) string
GetLog returns the contents of a logger.
This function must be only used with the direct output of TestLogger().
func RedisDeletePattern ¶
RedisDeletePattern deletes items from the redis database that match the given pattern.
func SetupTestDatabase ¶
SetupTestDatabase creates a database on the database server.
It returns the connection url of the new database and a function that will delete the database when it is run.
func TestLogger ¶
func TestLogger() logrus.FieldLogger
TestLogger creates a logger that saves its data instead of outputting it to the stdout.
func TestRegData ¶
TestRegData creates a random data set for a filled-in registration form.
Types ¶
type SubmittableForm ¶
type SubmittableForm interface {
Submit(postValues *url.Values, alter ...func(*http.Request)) *http.Response
}
SubmittableForm represents a form that is ready to be submitted with the given values.
type TestClient ¶
type TestClient struct { Page *goquery.Document LastRequest *http.Request LastResponse *http.Response // contains filtered or unexported fields }
TestClient is a mock http client, meant to be used in integration testing.
func (*TestClient) CurrentUID ¶
func (c *TestClient) CurrentUID() uuid.UUID
CurrentUID returns the current user's id.
func (*TestClient) FollowRedirect ¶
func (c *TestClient) FollowRedirect(alter ...func(*http.Request)) *http.Response
FollowRedirect follows a redirect if applicable.
func (*TestClient) Form ¶
func (c *TestClient) Form(url string, alter ...func(*http.Request)) SubmittableForm
Form requests a form page, and parses the necessary data so it can be submitted easily.
func (*TestClient) FormValues ¶
func (c *TestClient) FormValues(formid string) *url.Values
FormValues parses the existing form values on a form page.
This is useful for edit forms, or testing form submission errors.
func (*TestClient) RegistrationAndLogin ¶
func (c *TestClient) RegistrationAndLogin(regdata *url.Values)
RegistrationAndLogin emulates a registration and a login of an account.
type TestMailer ¶
type TestMailer struct {
Messages []Message
}
TestMailer is an in-memory implementation of the Mailer interface.
func NewTestMailer ¶
func NewTestMailer() *TestMailer
func (*TestMailer) From ¶
func (m *TestMailer) From() string
type TestSite ¶
type TestSite struct { Server *server.Server Mailer *TestMailer // contains filtered or unexported fields }
TestSite represents a version of *site.Site that is meant to be used for general integration testing.
func SetupTestSite ¶
SetupTestSite creates a test site.
func SetupTestSiteFromEnv ¶
func SetupTestSiteFromEnv() *TestSite
SetupTestSiteFromEnv creates a test site from environment variables.
func (*TestSite) Cleanup ¶
func (ts *TestSite) Cleanup()
Cleanup cleans the database and redis.
This function is meant to be deferred after CreateTestSite is called.
func (*TestSite) CreateClient ¶
func (ts *TestSite) CreateClient(t *testing.T) *TestClient
CreateClient creates a mock http client for the test site.
This client has its own separate cookie storage.