Documentation
¶
Overview ¶
Package testkit has the helpers shared by the service tests: an isolated Mongo database, an Elasticsearch recorder, token signing and an HTTP client for handlers.
Tests that need Mongo are skipped unless MONGO_TEST_URI is set, e.g. mongodb://localhost:27018/?directConnection=true (make env-up).
Index ¶
- func DisabledAuth(t testing.TB) *auth.Authenticator
- func GuardedMongo(t testing.TB, db *mongo.Database) (*mongo.Database, *mongodb.WriteGuard)
- func Mongo(t testing.TB) *mongo.Database
- func MongoClient(t testing.TB) *mongo.Client
- func Store(t testing.TB, collection string) rest.Store
- type Client
- type DB
- type ESCall
- type ESRecorder
- type Keys
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisabledAuth ¶
func DisabledAuth(t testing.TB) *auth.Authenticator
DisabledAuth returns an authenticator that accepts every request.
func GuardedMongo ¶
GuardedMongo opens db again on a client of its own with a mongodb.WriteGuard, as app.Run does in dry run.
func MongoClient ¶
MongoClient returns a client shared by the tests of the package.
Types ¶
type Client ¶
type Client struct {
// Header is sent with every request (e.g. Authorization).
Header http.Header
// contains filtered or unexported fields
}
Client calls a handler in process.
func DryRun ¶
func DryRun(t testing.TB, spec app.Spec, cfg config.Config, authn *auth.Authenticator, db *mongo.Database) *Client
DryRun builds the service again on db, the database of Service, in dry run: the tests prepare the data with the real service and repeat the writes on this one. Background tasks registered with Env.Go and writes outside a transaction (mongodb.WriteGuard, as in app.Run) fail the test.
func Service ¶
func Service(t testing.TB, spec app.Spec, cfg config.Config, authn *auth.Authenticator) (*Client, *mongo.Database)
Service builds a whole service (app.Build) on an isolated database and returns a client for it.
type ESRecorder ¶
type ESRecorder struct {
*httptest.Server
// Fail makes every request answer 500.
Fail bool
// contains filtered or unexported fields
}
ESRecorder is a fake Elasticsearch that records the writes.
func (*ESRecorder) Calls ¶
func (es *ESRecorder) Calls() []ESCall
Calls returns the recorded writes.
func (*ESRecorder) Hosts ¶
func (es *ESRecorder) Hosts() []any
Hosts is the value for elasticsearch.hosts.
type Keys ¶
type Keys struct {
// PublicKeyFile is the PEM file to configure auth.Config.PublicKeyFile.
PublicKeyFile string
// contains filtered or unexported fields
}
Keys signs legacy auth-api tokens for tests.
func (*Keys) Authenticator ¶
func (k *Keys) Authenticator(t testing.TB) *auth.Authenticator
Authenticator returns an enabled authenticator that accepts Token.