integration

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// StandardClaims is the standard payload inside a test JWT
	StandardClaims = jwt.MapClaims{
		auth.MultiTenancyField: "TestAccount",
	}
)

Functions

func AppendTokenToOutgoingContext

func AppendTokenToOutgoingContext(ctx context.Context, fieldName, token string) context.Context

AppendTokenToOutgoingContext adds an authorization token to the gRPC request context metadata. The user must provide a token field name like "token" or "bearer" to this function. It is intended specifically for gRPC testing.

Example (Output)
// make the jwt
authToken, err := jwt.NewWithClaims(
	jwt.SigningMethodHS256, jwt.MapClaims{
		"user":  "user-test",
		"roles": "admin",
	},
).SignedString([]byte("some-secret"))
if err != nil {
	log.Fatalf("unable to build token: %v", err)
}
// add the jwt to context
ctxBearer := AppendTokenToOutgoingContext(
	context.Background(), "Bearer", authToken,
)
// check to make sure the token was added
md, ok := metadata.FromOutgoingContext(ctxBearer)
if !ok || len(md["authorization"]) < 1 {
	log.Fatalf("unable to get token from context: %v", err)
}
fields := strings.Split(md["authorization"][0], " ")
if len(fields) < 2 {
	log.Fatalf("unexpected authorization metadata: %v", fields)
}
fmt.Println(fields[0] == "Bearer")
fmt.Println(fields[1] == authToken)
Output:

true
true

func BuildGoSource

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

BuildGoSource builds a target Go package and gives the resulting binary some user-defined name. The function returned by BuildGoSource will remove the binary that got created.

func GetOpenPort

func GetOpenPort() (int, error)

GetOpenPort searches for an open port on the host

func GetOpenPortInRange

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

GetOpenPortInRange finds the first unused port within specific range

func MakeStandardRequest

func MakeStandardRequest(method, url string, payload interface{}) (*http.Request, error)

MakeStandardRequest issues an HTTP request a specific endpoint with Atlas-specific request data (e.g. the authorization token)

func MakeTestJWT

func MakeTestJWT(method jwt.SigningMethod, claims jwt.Claims) (string, error)

MakeTestJWT generates a token string based on the given JWT claims

func NewTestPostgresDB

func NewTestPostgresDB(opts ...option) (testPostgresDB, error)

NewTestPostgresDB returns a test postgres database that the functional options that have been provided by the caller

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

func StandardTestJWT

func StandardTestJWT() (string, error)

StandardTestJWT builds a JWT with the standard test claims in the JWT payload

func StandardTestingContext

func StandardTestingContext() (context.Context, error)

StandardTestingContext returns an outgoing request context that includes the standard test JWT. It is intended specifically for gRPC testing.

func WithMigrateDownFunction

func WithMigrateDownFunction(migrateDownFunction func(*sql.DB) error) func(*testPostgresDB)

WithMigrateFunction is used to tear down the test Postgres according to a specific set of migrations. It runs on a per-test basis whenever the Reset() function is called.

func WithMigrateUpFunction

func WithMigrateUpFunction(migrateUpFunction func(*sql.DB) error) func(*testPostgresDB)

WithMigrateFunction is used to rebuild the test Postgres database on a per-test basis. Whenever the database is reset with the Reset() function, the migrateUp function will rebuild the tables.

func WithName

func WithName(name string) func(*testPostgresDB)

WithName is used to specify the name of the test Postgres database. By default the database name is "test-postgres-db"

func WithPassword

func WithPassword(password string) func(*testPostgresDB)

WithPassword is used to specify the password of the test Postgres database

func WithPort

func WithPort(port int) func(*testPostgresDB)

WithPort is used to specify the port of the test Postgres database. By default, the test database will find the first open port in the 35000+ range

func WithTimeout

func WithTimeout(timeout time.Duration) func(*testPostgresDB)

WithTimeout is used to specify a connection timeout to the database

func WithUser

func WithUser(user string) func(*testPostgresDB)

WithUser is used to specify the name of the Postgres user that owns the test database

func WithVersion

func WithVersion(version string) func(*testPostgresDB)

WithVersion is used to specify the version of the test Postgres database. By default the version is "latest"

Types

This section is empty.

Jump to

Keyboard shortcuts

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