testutil

package
v0.0.0-...-dc37515 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

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 Must

func Must(err error)

Must panics if err is not nil.

func RedisDeletePattern

func RedisDeletePattern(client *redis.Client, pattern string) error

RedisDeletePattern deletes items from the redis database that match the given pattern.

func SetupTestDatabase

func SetupTestDatabase(dburl string) (string, func())

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

func TestRegData() *url.Values

TestRegData creates a random data set for a filled-in registration form.

Types

type Message

type Message struct {
	To      []string
	Message []byte
}

Message represents a sent email.

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 (c *TestClient) ClickLink(selector string, alter ...func(*http.Request)) *http.Response

ClickLink emulates clicking on a link.

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.

func (*TestClient) Request

func (c *TestClient) Request(method, target string, body io.Reader, alter ...func(*http.Request)) *http.Response

Request emulates sending a request to the test site.

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

func (*TestMailer) Send

func (m *TestMailer) Send(to []string, msg []byte) error

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

func SetupTestSite(dburl, redisurl string) *TestSite

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.

func (*TestSite) Database

func (ts *TestSite) Database() database.DB

func (*TestSite) KeyValueStore

func (ts *TestSite) KeyValueStore() keyvalue.Store

Jump to

Keyboard shortcuts

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