integration

package
v0.0.0-...-2502acc Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TestSecret dummy secret used for signing test JWTs
	TestSecret = "some-secret-123"
)

Variables

View Source
var (
	// DefaultClaims is the standard payload inside a test JWT
	DefaultClaims = jwt.MapClaims{"AccountID": "TestAccount"}
)

Functions

func AddDefaultTokenToRequest

func AddDefaultTokenToRequest(req *http.Request)

AddDefaultTokenToRequest adds the default authorization token to the http header of a given http request

func AddTokenToRequest

func AddTokenToRequest(key, token string, req *http.Request)

AddTokenToRequest adds an authorization token to the http request header

func BuildSource

func BuildSource(packagePath, output string) (func() error, error)

BuildSource builds a target Go package and gives the resulting binary some user-defined name

func ContextWithToken

func ContextWithToken(ctx context.Context, token string) context.Context

ContextWithToken creates a context with a jwt

func DefaultContext

func DefaultContext(t *testing.T) context.Context

DefaultContext returns a context that has a jwt for basic testing purposes

func GetOpenPortInRange

func GetOpenPortInRange(lowerBound, upperBound int) (int, error)

GetOpenPortInRange finds an unused port within a specified range

func MakeRequestWithDefaults

func MakeRequestWithDefaults(method, url string, payload interface{}) (*http.Response, error)

MakeRequestWithDefaults issues request that contains the necessary parameters request to reach the contacts application (e.g. an authorization token)

func MakeToken

func MakeToken(claims jwt.Claims) (string, error)

MakeToken generates a token string based on the given jwt claims

func RunBinary

func RunBinary(binPath string, args ...string) (func(), error)

RunBinary runs a target binary with a set of arguments provided by the user

func RunContainer

func RunContainer(image string, dockerArgs, runtimeArgs []string) (func() error, error)

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

Jump to

Keyboard shortcuts

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