Documentation ¶
Index ¶
- Constants
- Variables
- func AddDefaultTokenToRequest(req *http.Request)
- func AddTokenToRequest(key, token string, req *http.Request)
- func BuildSource(packagePath, output string) (func() error, error)
- func ContextWithToken(ctx context.Context, token string) context.Context
- func DefaultContext(t *testing.T) context.Context
- func GetOpenPortInRange(lowerBound, upperBound int) (int, error)
- func MakeRequestWithDefaults(method, url string, payload interface{}) (*http.Response, error)
- func MakeToken(claims jwt.Claims) (string, error)
- func RunBinary(binPath string, args ...string) (func(), error)
- func RunContainer(image string, dockerArgs, runtimeArgs []string) (func() error, error)
- type PostgresDBConfig
Constants ¶
const (
// TestSecret dummy secret used for signing test JWTs
TestSecret = "some-secret-123"
)
Variables ¶
var ( // DefaultClaims is the standard payload inside a test JWT DefaultClaims = jwt.MapClaims{"AccountID": "TestAccount"} )
Functions ¶
func AddDefaultTokenToRequest ¶
AddDefaultTokenToRequest adds the default authorization token to the http header of a given http request
func AddTokenToRequest ¶
AddTokenToRequest adds an authorization token to the http request header
func BuildSource ¶
BuildSource builds a target Go package and gives the resulting binary some user-defined name
func ContextWithToken ¶
ContextWithToken creates a context with a jwt
func DefaultContext ¶
DefaultContext returns a context that has a jwt for basic testing purposes
func GetOpenPortInRange ¶
GetOpenPortInRange finds an unused port within a specified range
func MakeRequestWithDefaults ¶
MakeRequestWithDefaults issues request that contains the necessary parameters request to reach the contacts application (e.g. an authorization token)
func RunContainer ¶
RunContainer launches a detached docker container on the host machine. It takes an image name, a list of "docker run" arguments, and a list of arguments that get passed to the container runtime
Types ¶
type PostgresDBConfig ¶
type PostgresDBConfig struct { Host string Port int DBName string DBUser string DBPassword string DBVersion string MigrateFunction func(sql.DB) error }
PostgresDBConfig models a test Postgres database
func NewTestPostgresDB ¶
func NewTestPostgresDB(dbName string, migrateFunction func(sql.DB) error) (*PostgresDBConfig, error)
NewTestPostgresDB creates a PostgresDBConfig with a sensible set of database defaults
func (PostgresDBConfig) GetDSN ¶
func (cfg PostgresDBConfig) GetDSN() string
GetDSN returns the database connection string for the test Postgres database
func (PostgresDBConfig) Reset ¶
func (cfg PostgresDBConfig) Reset(t *testing.T)
Reset drops all the tables in a test database and regenerates them by running migrations. If a migrationFunction has not been specified, then the tables are dropped but not regenerated
func (PostgresDBConfig) RunAsDockerContainer ¶
func (cfg PostgresDBConfig) RunAsDockerContainer(containerName string) (func() error, error)
RunAsDockerContainer uses the Postgres configuration to run a Postgres Docker container on the host machine