Documentation ¶
Overview ¶
Package envstest defines global test helpers for the entire project.
Index ¶
- Constants
- func AutoConfirmDialogs(ctx context.Context, b bool) <-chan error
- func CaptureJavascriptErrors(ctx context.Context) <-chan error
- func ExerciseBadPagination(t *testing.T, membership *database.Membership, h http.Handler)
- func ExerciseIDNotFound(t *testing.T, membership *database.Membership, h http.Handler)
- func ExerciseMembershipMissing(t *testing.T, h http.Handler)
- func ExercisePermissionMissing(t *testing.T, h http.Handler)
- func ExerciseSessionMissing(t *testing.T, h http.Handler)
- func LocalesPath() string
- func NewFailingDatabase() *gorm.DB
- func NewHarnessServer(tb testing.TB, mux http.Handler) *server.Server
- func ServerAssetsPath() string
- type APIServerConfigResponse
- type APIServerResponse
- type AdminAPIServerConfigResponse
- type AdminAPIServerResponse
- type BootstrapResponse
- type IntegrationSuite
- type SQLConn
- func (c *SQLConn) Begin() (driver.Tx, error)
- func (c *SQLConn) BeginTx() (driver.Tx, error)
- func (c *SQLConn) Close() error
- func (c *SQLConn) Commit() error
- func (c *SQLConn) Exec(query string, args []driver.Value) (driver.Result, error)
- func (c *SQLConn) Prepare(query string) (driver.Stmt, error)
- func (c *SQLConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (c *SQLConn) Query(query string, args []driver.Value) (driver.Rows, error)
- func (c *SQLConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (c *SQLConn) Rollback() error
- type SQLDriver
- type ServerConfigResponse
- type TestHarnessResponse
- type TestServerResponse
- func (r *TestServerResponse) LoggedInSession(session *sessions.Session, email string) (*sessions.Session, error)
- func (r *TestServerResponse) ProvisionAndLogin() (*database.Realm, *database.User, *sessions.Session, error)
- func (r *TestServerResponse) SessionCookie(session *sessions.Session) (*http.Cookie, error)
Constants ¶
const ( RealmName = "e2e-test-realm" RegionCode = "e2e-test" AdminKeyPrefix = "e2e-admin-key." DeviceKeyPrefix = "e2e-device-key." StatsKeyPrefix = "e2e-stats-key." AndroidAppPrefix = "e2e-android-" IOSAppPrefix = "e2e-ios-" )
Variables ¶
This section is empty.
Functions ¶
func AutoConfirmDialogs ¶ added in v0.19.0
AutoConfirmDialogs automatically clicks "confirm" on popup dialogs from window.Confirm prompts.
func CaptureJavascriptErrors ¶ added in v0.19.0
CaptureJavascriptErrors captures any console errors that occur.
func ExerciseBadPagination ¶ added in v0.19.0
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
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
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
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
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
NewFailingDatabase database creates a new database connection that fails all requests.
func NewHarnessServer ¶ added in v0.19.0
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
func (r *APIServerConfigResponse) NewServer(tb testing.TB) *APIServerResponse
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.
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
func (r *AdminAPIServerConfigResponse) NewServer(tb testing.TB) *AdminAPIServerResponse
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.
type BootstrapResponse ¶ added in v0.20.0
type BootstrapResponse struct { Realm *database.Realm AdminAPIKey string DeviceAPIKey string StatsAPIKey string // contains filtered or unexported fields }
BootstrapResponse is the response from Bootstrap.
func Bootstrap ¶ added in v0.20.0
func Bootstrap(db *database.Database) (*BootstrapResponse, error)
Bootstrap configures the database with an e2e realm (or re-uses one that already exists), and provisions new authorized apps for accessing the admin apis, device apis, and stats apis.
Callers should always call Cleanup() on the response to ensure temporary resources are purged.
func (*BootstrapResponse) Cleanup ¶ added in v0.20.0
func (r *BootstrapResponse) Cleanup() error
Cleanup deletes temporary resources created by the bootstrap.
type IntegrationSuite ¶ added in v0.20.0
type IntegrationSuite struct {
// contains filtered or unexported fields
}
IntegrationSuite encompasses a local API server and Admin API server for testing. Both servers run in-memory on the local machine.
func NewIntegrationSuite ¶ added in v0.20.0
func NewIntegrationSuite(tb testing.TB) *IntegrationSuite
NewIntegrationSuite creates a new test suite for local integration testing.
func (*IntegrationSuite) APIServerClient ¶ added in v0.20.0
func (i *IntegrationSuite) APIServerClient() *clients.APIServerClient
APIServerClient returns the API server client.
func (*IntegrationSuite) AdminAPIServerClient ¶ added in v0.20.0
func (i *IntegrationSuite) AdminAPIServerClient() *clients.AdminAPIServerClient
AdminAPIServerClient returns the Admin API client.
type SQLConn ¶ added in v0.19.0
type SQLConn struct{}
func (*SQLConn) PrepareContext ¶ added in v0.19.0
func (*SQLConn) QueryContext ¶ added in v0.19.0
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.
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
func (r *ServerConfigResponse) NewServer(tb testing.TB) *TestServerResponse
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 ¶
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.