envstest

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package envstest defines global test helpers for the entire project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoConfirmDialogs added in v0.19.0

func AutoConfirmDialogs(ctx context.Context, b bool) <-chan error

AutoConfirmDialogs automatically clicks "confirm" on popup dialogs from window.Confirm prompts.

func CaptureJavascriptErrors added in v0.19.0

func CaptureJavascriptErrors(ctx context.Context) <-chan error

CaptureJavascriptErrors captures any console errors that occur.

func ExerciseBadPagination added in v0.19.0

func ExerciseBadPagination(t *testing.T, membership *database.Membership, h http.Handler)

ExerciseBadPagination tests that the proper response code and HTML error page are rendered when the URL includes pagination parameters that fail to parse.

func ExerciseIDNotFound added in v0.19.0

func ExerciseIDNotFound(t *testing.T, membership *database.Membership, h http.Handler)

ExerciseIDNotFound tests that the proper response code and HTML error page are rendered when the route expects an "id" mux parameter, but the one given does not correspond to an actual record.

func ExerciseMembershipMissing added in v0.19.0

func ExerciseMembershipMissing(t *testing.T, h http.Handler)

ExerciseMembershipMissing tests that the proper response code and HTML error page are rendered with there is no membership in the context. It sets a session in the context.

func ExercisePermissionMissing added in v0.19.0

func ExercisePermissionMissing(t *testing.T, h http.Handler)

ExercisePermissionMissing tests that the proper response code and HTML error page are rendered when the requestor does not have permission to perform this action.

func ExerciseSessionMissing added in v0.19.0

func ExerciseSessionMissing(t *testing.T, h http.Handler)

ExerciseSessionMissing tests that the proper response code and HTML error page are rendered with the context has no session.

func LocalesPath added in v0.17.0

func LocalesPath() string

LocalesPath returns the path to the i18n locales.

func NewFailingDatabase added in v0.19.0

func NewFailingDatabase() *gorm.DB

NewFailingDatabase database creates a new database connection that fails all requests.

func NewHarnessServer added in v0.19.0

func NewHarnessServer(tb testing.TB, mux http.Handler) *server.Server

NewHarnessServer creates a new server for the mux on a random port. Cleanup is handled automatically.

func ServerAssetsPath

func ServerAssetsPath() string

ServerAssetsPath returns the path to the UI server assets.

Types

type APIServerConfigResponse added in v0.19.0

type APIServerConfigResponse struct {
	Config      *config.APIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	KeyManager  keys.KeyManager
	RateLimiter limiter.Store
}

APIServerConfigResponse is the response from creating an API server config.

func NewAPIServerConfig added in v0.19.0

func NewAPIServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *APIServerConfigResponse

NewAPIServerConfig creates a new API server configuration.

func (*APIServerConfigResponse) NewServer added in v0.19.0

type APIServerResponse added in v0.19.0

type APIServerResponse struct {
	Config      *config.APIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	KeyManager  keys.KeyManager
	RateLimiter limiter.Store
	Server      *server.Server
}

APIServerResponse is the response from a test APIServer instance.

func NewAPIServer added in v0.19.0

func NewAPIServer(tb testing.TB, testDatabaseInstance *database.TestInstance) *APIServerResponse

NewAPIServer creates a new test APIServer server instance. See NewHarnessServer for more information.

func (*APIServerResponse) NewAPIServerClient added in v0.19.0

func (r *APIServerResponse) NewAPIServerClient(tb testing.TB) *clients.APIServerClient

NewAPIServerClient creates a new API key and returns a client authorized with that API key. The generated API key is cleaned up by t.

type AdminAPIServerConfigResponse added in v0.19.0

type AdminAPIServerConfigResponse struct {
	Config      *config.AdminAPIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	RateLimiter limiter.Store
}

AdminAPIServerConfigResponse is the response from creating an AdminAPI server config.

func NewAdminAPIServerConfig added in v0.19.0

func NewAdminAPIServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *AdminAPIServerConfigResponse

NewAdminAPIServerConfig creates a new API server configuration.

func (*AdminAPIServerConfigResponse) NewServer added in v0.19.0

NewServer creates a new server.

type AdminAPIServerResponse added in v0.19.0

type AdminAPIServerResponse struct {
	Config      *config.AdminAPIServerConfig
	Database    *database.Database
	Cacher      cache.Cacher
	RateLimiter limiter.Store
	Server      *server.Server
}

AdminAPIServerResponse is the response from a test AdminAPI instance.

func NewAdminAPIServer added in v0.19.0

func NewAdminAPIServer(tb testing.TB, testDatabaseInstance *database.TestInstance) *AdminAPIServerResponse

NewAdminAPIServer creates a new test AdminAPI server instance. See NewHarnessServer for more information.

func (*AdminAPIServerResponse) NewAdminAPIServerClient added in v0.19.0

func (r *AdminAPIServerResponse) NewAdminAPIServerClient(tb testing.TB) *clients.AdminAPIServerClient

NewAdminAPIServerClient creates a new API key and returns a client authorized with that API key. The generated API key is cleaned up by t.

type SQLConn added in v0.19.0

type SQLConn struct{}

func (*SQLConn) Begin added in v0.19.0

func (c *SQLConn) Begin() (driver.Tx, error)

func (*SQLConn) BeginTx added in v0.19.0

func (c *SQLConn) BeginTx() (driver.Tx, error)

func (*SQLConn) Close added in v0.19.0

func (c *SQLConn) Close() error

func (*SQLConn) Commit added in v0.19.0

func (c *SQLConn) Commit() error

func (*SQLConn) Exec added in v0.19.0

func (c *SQLConn) Exec(query string, args []driver.Value) (driver.Result, error)

func (*SQLConn) Prepare added in v0.19.0

func (c *SQLConn) Prepare(query string) (driver.Stmt, error)

func (*SQLConn) PrepareContext added in v0.19.0

func (c *SQLConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

func (*SQLConn) Query added in v0.19.0

func (c *SQLConn) Query(query string, args []driver.Value) (driver.Rows, error)

func (*SQLConn) QueryContext added in v0.19.0

func (c *SQLConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

func (*SQLConn) Rollback added in v0.19.0

func (c *SQLConn) Rollback() error

type SQLDriver added in v0.19.0

type SQLDriver struct{}

SQLDriver is a test SQL driver implementation that returns an error for most queries and operations. It's used to test how the system behaves under connection errors or other database-level failures.

func (*SQLDriver) Connect added in v0.19.0

func (d *SQLDriver) Connect(ctx context.Context) (driver.Conn, error)

func (*SQLDriver) Driver added in v0.19.0

func (d *SQLDriver) Driver() driver.Driver

func (*SQLDriver) Open added in v0.19.0

func (d *SQLDriver) Open(name string) (driver.Conn, error)

type ServerConfigResponse added in v0.19.0

type ServerConfigResponse struct {
	AuthProvider auth.Provider
	Config       *config.ServerConfig
	Database     *database.Database
	Cacher       cache.Cacher
	KeyManager   keys.KeyManager
	RateLimiter  limiter.Store
}

ServerConfigResponse is the response from creating a server config.

func NewServerConfig added in v0.19.0

func NewServerConfig(tb testing.TB, testDatabaseInstance *database.TestInstance) *ServerConfigResponse

NewServerConfig creates a new server configuration. It creates all the keys, databases, and cacher, but does not actually start the server. All cleanup is scheduled by t.Cleanup.

func (*ServerConfigResponse) NewServer added in v0.19.0

type TestHarnessResponse added in v0.19.0

type TestHarnessResponse struct {
	Cacher      cache.Cacher
	CacheConfig *cache.Config

	Database       *database.Database
	DatabaseConfig *database.Config

	ObservabilityConfig *observability.Config

	KeyManager       keys.KeyManager
	KeyManagerConfig *keys.Config

	RateLimiter       limiter.Store
	RateLimiterConfig *ratelimit.Config
}

func NewTestHarness added in v0.19.0

func NewTestHarness(tb testing.TB, testDatabaseInstance *database.TestInstance) *TestHarnessResponse

type TestServerResponse

type TestServerResponse struct {
	AuthProvider auth.Provider
	Cacher       cache.Cacher
	Config       *config.ServerConfig
	Database     *database.Database
	KeyManager   keys.KeyManager
	RateLimiter  limiter.Store
	Server       *server.Server
}

TestServerResponse is used as the reply to creating a test UI server.

func NewServer

func NewServer(tb testing.TB, testDatabaseInstance *database.TestInstance) *TestServerResponse

NewServer creates a new test UI server instance. See NewHarnessServer for more information.

func (*TestServerResponse) LoggedInSession added in v0.16.0

func (r *TestServerResponse) LoggedInSession(session *sessions.Session, email string) (*sessions.Session, error)

LoggedInSession returns an session with the provided email address logged in. It also stores that email verification and MFA prompting have already occurred for a consistent post-login experience.

The provided email is marked as verified, has MFA enabled, and is not revoked. To test other journeys, manually build the session.

func (*TestServerResponse) ProvisionAndLogin added in v0.19.0

func (r *TestServerResponse) ProvisionAndLogin() (*database.Realm, *database.User, *sessions.Session, error)

ProvisionAndLogin provisions and authenticates the initial user, realm, permissions on the realm, and session cookie.

func (*TestServerResponse) SessionCookie

func (r *TestServerResponse) SessionCookie(session *sessions.Session) (*http.Cookie, error)

SessionCookie returns an encrypted cookie for the given session information, capable of being injected into the browser instance and read by the application. Since the cookie contains the session, it can be used to mutate any server state, including the currently-authenticated user.

Jump to

Keyboard shortcuts

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