tests

package
v0.0.0-...-3735483 Latest Latest
Warning

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

Go to latest
Published: May 11, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

README

FN integration API tests

These are tests that can either run locally against the current codebase (e.g. in an IDE) or remotely against a running Fn instance.

Test dependencies

DOCKER_HOST - for building images
FN_API_URL - Fn API endpoint - leave this unset to test using the local codebase

How to run tests?

export FN_API_URL=http://localhost:8080
go test -v ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APICallWithRetry

func APICallWithRetry(t *testing.T, attempts int, sleep time.Duration, callback func() error) (err error)

func APIClient

func APIClient() *client.Fn

func AnnotationsEquivalent

func AnnotationsEquivalent(md1, md2 map[string]interface{}) bool

AnnotationsEquivalent checks if two annotations maps are semantically equivalent, including nil == empty map

func AssertRouteMatches

func AssertRouteMatches(t *testing.T, expected *models.Route, got *models.Route)

func CallFN

func CallFN(u string, content io.Reader, output io.Writer, method string, env []string) (http.Header, error)

func ConfigEquivalent

func ConfigEquivalent(a map[string]string, b map[string]string) bool

ConfigEquivalent checks if two config objects are semantically equivalent (including nils)

func EnvAsHeader

func EnvAsHeader(req *http.Request, selectedEnv []string)

func GetAPIURL

func GetAPIURL() (string, *url.URL)

func Host

func Host() string

func RandStringBytes

func RandStringBytes(n int) string

Types

type TestHarness

type TestHarness struct {
	Context      context.Context
	Cancel       func()
	Client       *client.Fn
	AppName      string
	RoutePath    string
	Image        string
	RouteType    string
	Format       string
	Memory       uint64
	Timeout      int32
	IdleTimeout  int32
	RouteConfig  map[string]string
	RouteHeaders map[string][]string
	// contains filtered or unexported fields
}

TestHarness provides context and pre-configured clients to an individual test, it has some helper functions to create Apps and Routes that mirror the underlying client operations and clean them up after the test is complete This is not goroutine safe and each test case should use its own harness.

func SetupHarness

func SetupHarness() *TestHarness

SetupHarness creates a test harness for a test case - this picks up external options and

func (*TestHarness) AppMustExist

func (s *TestHarness) AppMustExist(t *testing.T, appName string) *models.App

AppMustExist fails the test if the specified app does not exist

func (*TestHarness) BasicRoute

func (s *TestHarness) BasicRoute() *models.Route

func (*TestHarness) Cleanup

func (s *TestHarness) Cleanup()

func (*TestHarness) GivenAppExists

func (s *TestHarness) GivenAppExists(t *testing.T, app *models.App)

GivenAppExists creates an app and ensures it is deleted on teardown, this fatals if the app is not created

func (*TestHarness) GivenRouteExists

func (s *TestHarness) GivenRouteExists(t *testing.T, appName string, route *models.Route)

GivenRouteExists creates a route using the specified arguments, failing the test if the creation fails, this tears down any apps that are created when the test is complete

func (*TestHarness) GivenRoutePatched

func (s *TestHarness) GivenRoutePatched(t *testing.T, appName, routeName string, rt *models.Route)

GivenRoutePatched applies a patch to a route, failing the test if this fails.

func (*TestHarness) PostApp

func (s *TestHarness) PostApp(app *models.App) (*apps.PostAppsOK, error)

PostApp creates an app and esures it is deleted on teardown if it was created

func (*TestHarness) PostRoute

func (s *TestHarness) PostRoute(appName string, route *models.Route) (*routes.PostAppsAppRoutesOK, error)

PostRoute Creates a route and deletes the corresponding app (if created) on teardown

func (*TestHarness) PutRoute

func (s *TestHarness) PutRoute(appName string, routePath string, route *models.Route) (*routes.PutAppsAppRoutesRouteOK, error)

PutRoute creates a route via PUT, tearing down any apps that are created when the test is complete

func (*TestHarness) RouteMustExist

func (s *TestHarness) RouteMustExist(t *testing.T, appName string, routePath string) *models.Route

RouteMustExist checks that a route exists, failing the test if it doesn't, returns the route

Directories

Path Synopsis
fn
log

Jump to

Keyboard shortcuts

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