testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package testutil is a generated GoMock package.

Index

Constants

View Source
const (
	// EnvDockerRegistry is the environment variable used to store the
	// registry we will push containers to for the integration tests. If this
	// is not set, then the integration tests are skipped.
	EnvDockerRegistry = "DOCKER_REGISTRY"

	// IntegrationTestDomain is the domain that the integration test spaces
	// are setup with.
	IntegrationTestDomain = "integration-tests.kf.dev"
)

Variables

This section is empty.

Functions

func AppFromContext

func AppFromContext(ctx context.Context) string

AppFromContext returns the service plan name given a context that has been setup via ContextWithApp.

func Assert

func Assert(t Failable, m gomock.Matcher, actual interface{})

Assert causes a test to fail if the two values are not DeepEqual to one another.

func AssertContainsAll

func AssertContainsAll(t Failable, haystack string, needles []string)

AssertContainsAll validates that all of the search strings were in the main string. Case-insensitive.

func AssertEqual

func AssertEqual(t Failable, fieldName string, expected, actual interface{})

AssertEqual causes a test to fail if the two values are not DeepEqual to one another.

func AssertErrorContainsAll

func AssertErrorContainsAll(t Failable, errorMsg error, expected []string)

AssertErrorContainsAll checks that all of the search strings were in the error message. Case-insensitive.

func AssertErrorsEqual

func AssertErrorsEqual(t Failable, expected, actual error)

AssertErrorsEqual checks that the values of the two errors match.

func AssertJSONEqual

func AssertJSONEqual(t Failable, expected, actual string)

AssertJSONEqual ensures the expexted JSON matches the actual JSON.

func AssertKeyWithValue

func AssertKeyWithValue(t Failable, m map[interface{}]interface{}, key, value interface{})

AssertKeyWithValue ensures the key is present in the map and has the given value.

func AssertNil

func AssertNil(t Failable, name string, value interface{})

AssertNil fails the test if the value is not nil.

func AssertNotBlank

func AssertNotBlank(t Failable, name string, value string)

AssertNotBlank is used to validate that strings are not just made of whitespace.

func AssertNotNil

func AssertNotNil(t Failable, name string, value interface{})

AssertNotNil fails the test if the value is nil.

func AssertRegexp

func AssertRegexp(t Failable, fieldName, pattern, actual string)

AssertRegexp causes a test to fail if the value does not match a pattern.

func BrokerFromContext

func BrokerFromContext(ctx context.Context) string

BrokerFromContext returns the broker name given a context that has been setup via ContextWithBroker.

func CancelOnSignal

func CancelOnSignal(ctx context.Context, cancel func(), log func(args ...interface{}))

CancelOnSignal watches for a kill signal. If it gets one, it invokes the cancel function. An aditional signal will exit the process. If the given context finishes, the underlying go-routine finishes.

func CombineOutput

func CombineOutput(ctx context.Context, t *testing.T, out KfTestOutput) <-chan string

CombineOutput writes the Stdout and Stderr to a channel for each line.

func CombineOutputStr

func CombineOutputStr(ctx context.Context, t *testing.T, out KfTestOutput) []string

CombineOutputStr writes the Stdout and Stderr string. It will return when ctx is done.

func Compile

func Compile(ctx context.Context, t *testing.T, codePath string) string

Compile compiles a path in the repo. It returns a path to the resulting binary. codePath must be relative to RootDir.

func CompileKf

func CompileKf(ctx context.Context, t *testing.T) string

CompileKf compiles the `kf` binary. It returns a string to the resulting binary.

func ContextWithApp

func ContextWithApp(ctx context.Context, appName string) context.Context

ContextWithApp returns a context that has the app information. The app name can be fetched via AppFromContext.

func ContextWithBroker

func ContextWithBroker(ctx context.Context, brokerName string) context.Context

ContextWithBroker returns a context that has the service broker information. The broker name can be fetched via BrokerFromContext.

func ContextWithServiceClass

func ContextWithServiceClass(ctx context.Context, serviceClassName string) context.Context

ContextWithServiceClass returns a context that has the service class information. The service class name can be fetched via ServiceClassFromContext.

func ContextWithServiceInstance

func ContextWithServiceInstance(ctx context.Context, serviceInstanceName string) context.Context

ContextWithServiceInstance returns a context that has the service instance information. The service instance name can be fetched via ServiceInstanceFromContext.

func ContextWithServicePlan

func ContextWithServicePlan(ctx context.Context, servicePlanName string) context.Context

ContextWithServicePlan returns a context that has the service plan information. The service plan name can be fetched via ServiceInstanceFromContext.

func ContextWithSpace

func ContextWithSpace(ctx context.Context, space string) context.Context

ContextWithSpace returns a context that has the space information. The space can be fetched via SpaceFromContext.

func DockerRegistry

func DockerRegistry() string

DockerRegistry returns the configured docker registry for the integration tests.

func ExpectedAddr

func ExpectedAddr(hostname, urlPath string) string

ExpectedAddr returns the expected address for integration tests given a hostname and URL path.

func Logf

func Logf(t *testing.T, format string, i ...interface{})

Logf will write to Stderr if testing.Verbose is true and t.Log otherwise. This is so logs will stream out instead of only being displayed at the end of the test.

func PanicOnError

func PanicOnError(ctx context.Context, t *testing.T, messagePrefix string, errs <-chan error)

PanicOnError launches a go routine and waits for either the context or an error. An error will result in a panic. Why a panic in a test? t.Fatal is not thread safe. T.Failed() is thread safe, therefore we can use that to prevent the panic.

func RetryGet added in v0.2.0

func RetryGet(
	ctx context.Context,
	t *testing.T,
	addr string,
	duration time.Duration,
	expectedStatusCode int,
) (*http.Response, func())

RetryGet will send a get request until successful, duration has been reached or context is done. A close function is returned for closing the sub-context.

func RetryOnPanic

func RetryOnPanic(ctx context.Context, t *testing.T, f func())

RetryOnPanic will retry the function if it panics (e.g., via PanicOnError) until the given context is cancelled or the given function succeeds without panicking.

func RetryPost

func RetryPost(
	ctx context.Context,
	t *testing.T,
	addr string,
	duration time.Duration,
	expectedStatusCode int,
	body string,
) (*http.Response, func())

RetryPost will post until successful, duration has been reached or context is done. A close function is returned for closing the sub-context.

func RootDir

func RootDir(ctx context.Context, t *testing.T) string

RootDir uses git to find the root of the directory. This is useful for tests (especially integration ones that compile things).

func RunIntegrationTest

func RunIntegrationTest(t *testing.T, test func(ctx context.Context, t *testing.T))

RunIntegrationTest skips the tests if testing.Short() is true (via --short flag) or if DOCKER_REGISTRY is not set. Otherwise it runs the given test.

func RunKfTest

func RunKfTest(t *testing.T, test KfTest)

RunKfTest runs 'kf' for integration tests. It first compiles 'kf' and then launches it as a sub-process. It will set the args and environment variables accordingly. It will run the given test with the resulting STDOUT, STDERR and STDIN. It will cleanup the sub-process on completion via the context.

func ServiceClassFromContext

func ServiceClassFromContext(ctx context.Context) string

ServiceClassFromContext returns the service class name given a context that has been setup via ContextWithServiceClass.

func ServiceInstanceFromContext

func ServiceInstanceFromContext(ctx context.Context) string

ServiceInstanceFromContext returns the service instance name given a context that has been setup via ContextWithServiceInstance.

func ServicePlanFromContext

func ServicePlanFromContext(ctx context.Context) string

ServicePlanFromContext returns the service plan name given a context that has been setup via ContextWithServicePlan.

func SpaceFromContext

func SpaceFromContext(ctx context.Context) string

SpaceFromContext returns the space name given a context that has been setup via ContextWithSpace.

func StreamOutput

func StreamOutput(ctx context.Context, t *testing.T, out KfTestOutput)

StreamOutput writes the output of KfTestOutput to the testing.Log if testing.Verbose is false and Stderr otherwise.

Types

type AppInfo

type AppInfo struct {
	Name           string
	RequestedState string
	Instances      string
	Memory         string
	Disk           string
	URLs           []string
}

AppInfo is the information returned by listing an app. It is returned by ListApp.

type Failable

type Failable interface {
	Helper()
	Fatalf(format string, args ...interface{})
	Name() string
}

Failable is an interface for testing.T like things. We can't use testing.TB which would be preferable because they explicitly set a private field on it to prevent others from implementing it.

type FakeApiServer

type FakeApiServer struct {
	// contains filtered or unexported fields
}

FakeApiServer is a mock of TestApiServer interface

func AddFakeReactor

func AddFakeReactor(fake Reactable, ctrl *gomock.Controller) *FakeApiServer

Adds a gomock compatible FakeApiServer to Kubernetes client-go testing.

func NewFakeApiServer

func NewFakeApiServer(ctrl *gomock.Controller) *FakeApiServer

NewFakeApiServer creates a new mock instance

func (*FakeApiServer) Create

Create mocks base method

func (*FakeApiServer) Delete

func (m *FakeApiServer) Delete(arg0 schema.GroupVersionResource, arg1, arg2 string) error

Delete mocks base method

func (*FakeApiServer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*FakeApiServer) Get

func (m *FakeApiServer) Get(arg0 schema.GroupVersionResource, arg1, arg2 string) (runtime.Object, error)

Get mocks base method

func (*FakeApiServer) List

List mocks base method

func (*FakeApiServer) Update

Update mocks base method

type FakeApiServerMockRecorder

type FakeApiServerMockRecorder struct {
	// contains filtered or unexported fields
}

FakeApiServerMockRecorder is the mock recorder for FakeApiServer

func (*FakeApiServerMockRecorder) Create

func (mr *FakeApiServerMockRecorder) Create(arg0, arg1, arg2 interface{}) *gomock.Call

Create indicates an expected call of Create

func (*FakeApiServerMockRecorder) Delete

func (mr *FakeApiServerMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*FakeApiServerMockRecorder) Get

func (mr *FakeApiServerMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call

Get indicates an expected call of Get

func (*FakeApiServerMockRecorder) List

func (mr *FakeApiServerMockRecorder) List(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

List indicates an expected call of List

func (*FakeApiServerMockRecorder) Update

func (mr *FakeApiServerMockRecorder) Update(arg0, arg1, arg2 interface{}) *gomock.Call

Update indicates an expected call of Update

type Kf

type Kf struct {
	// contains filtered or unexported fields
}

Kf provides a DSL for running integration tests.

func NewKf added in v0.2.0

func NewKf(t *testing.T, binaryPath string) *Kf

NewKf creates a Kf for running tests with.

func (*Kf) App added in v0.2.0

func (k *Kf) App(ctx context.Context, name string) json.RawMessage

App gets a single app by name and returns its JSON representation.

func (*Kf) Apps

func (k *Kf) Apps(ctx context.Context) map[string]AppInfo

Apps returns all the apps from `kf app`

func (*Kf) BindService

func (k *Kf) BindService(ctx context.Context, appName string, serviceInstanceName string, extraArgs ...string)

BindService runs the bind-service command.

func (*Kf) Bindings

func (k *Kf) Bindings(ctx context.Context, extraArgs ...string) []string

Bindings runs the services command.

func (*Kf) Buildpacks

func (k *Kf) Buildpacks(ctx context.Context) []string

Buildpacks runs the buildpacks command.

func (*Kf) CreateQuota

func (k *Kf) CreateQuota(ctx context.Context, quotaName string, extraArgs ...string) ([]string, error)

CreateQuota creates a resourcequota.

func (*Kf) CreateRoute

func (k *Kf) CreateRoute(ctx context.Context, domain string, extraArgs ...string)

CreateRoute runs the create-route command.

func (*Kf) CreateService

func (k *Kf) CreateService(ctx context.Context, serviceClass string, servicePlan string, serviceInstanceName string, extraArgs ...string)

CreateService runs the create-service command.

func (*Kf) CreateServiceBroker

func (k *Kf) CreateServiceBroker(ctx context.Context, brokerName string, url string, extraArgs ...string)

CreateServiceBroker runs the create-service-broker command.

func (*Kf) CreateSpace

func (k *Kf) CreateSpace(ctx context.Context, space string) []string

CreateSpace runs the create-space command.

func (*Kf) Delete

func (k *Kf) Delete(ctx context.Context, appName string, extraArgs ...string)

Delete deletes an application.

func (*Kf) DeleteQuota

func (k *Kf) DeleteQuota(ctx context.Context, quotaName string) ([]string, error)

DeleteQuota deletes a quota.

func (*Kf) DeleteRoute

func (k *Kf) DeleteRoute(ctx context.Context, domain string, extraArgs ...string)

DeleteRoute runs the delete-route command.

func (*Kf) DeleteService

func (k *Kf) DeleteService(ctx context.Context, serviceInstanceName string, extraArgs ...string)

DeleteService runs the delete-service command.

func (*Kf) DeleteServiceBroker

func (k *Kf) DeleteServiceBroker(ctx context.Context, brokerName string, extraArgs ...string)

DeleteServiceBroker runs the delete-service-broker command.

func (*Kf) DeleteSpace

func (k *Kf) DeleteSpace(ctx context.Context, space string) []string

DeleteSpace runs the create-space command.

func (*Kf) Doctor

func (k *Kf) Doctor(ctx context.Context)

Doctor runs the doctor command.

func (*Kf) Env

func (k *Kf) Env(ctx context.Context, appName string) map[string]string

Env displays the environment variables for an app.

func (*Kf) GetQuota

func (k *Kf) GetQuota(ctx context.Context, quotaName string) ([]string, error)

GetQuota returns information about a quota.

func (*Kf) Logs

func (k *Kf) Logs(ctx context.Context, appName string, extraArgs ...string) <-chan string

Logs displays the logs of an application.

func (*Kf) MapRoute added in v0.2.0

func (k *Kf) MapRoute(ctx context.Context, appName, domain string, extraArgs ...string)

MapRoute runs the map-route command.

func (*Kf) Marketplace

func (k *Kf) Marketplace(ctx context.Context, extraArgs ...string) []string

Marketplace runs the marketplace command and returns the output.

func (*Kf) Proxy

func (k *Kf) Proxy(ctx context.Context, appName string, port int)

Proxy starts a proxy for an application.

func (*Kf) ProxyRoute added in v0.2.0

func (k *Kf) ProxyRoute(ctx context.Context, routeHost string, port int)

ProxyRoute starts a proxy for a route.

func (*Kf) Push

func (k *Kf) Push(ctx context.Context, appName string, extraArgs ...string)

Push pushes an application.

func (*Kf) Quotas

func (k *Kf) Quotas(ctx context.Context) ([]string, error)

Quotas returns all the quotas from `kf quotas`

func (*Kf) Restart

func (k *Kf) Restart(ctx context.Context, appName string)

Restart restarts an application.

func (*Kf) Routes

func (k *Kf) Routes(ctx context.Context) []string

Routes runs the routes command.

func (*Kf) RunSynchronous added in v0.2.0

func (k *Kf) RunSynchronous(ctx context.Context, cfg KfTestConfig) (stdout, stderr []byte, err error)

RunSynchronous runs kf with the provided configuration and returns the results.

func (*Kf) Services

func (k *Kf) Services(ctx context.Context, extraArgs ...string) []string

Services runs the services command.

func (*Kf) SetEnv

func (k *Kf) SetEnv(ctx context.Context, appName, name, value string)

SetEnv sets the environment variable for an app.

func (*Kf) Spaces

func (k *Kf) Spaces(ctx context.Context) []string

Spaces returns all the spaces from `kf spaces`

func (*Kf) Stacks

func (k *Kf) Stacks(ctx context.Context) []string

Stacks runs the stacks command.

func (*Kf) Start

func (k *Kf) Start(ctx context.Context, appName string)

Start starts an application.

func (*Kf) Stop

func (k *Kf) Stop(ctx context.Context, appName string)

Stop stops an application.

func (*Kf) Target

func (k *Kf) Target(ctx context.Context, namespace string) []string

Target runs the target command.

func (*Kf) UnbindService

func (k *Kf) UnbindService(ctx context.Context, appName string, serviceInstanceName string, extraArgs ...string)

UnbindService runs the unbind-service command.

func (*Kf) UnmapRoute added in v0.2.0

func (k *Kf) UnmapRoute(ctx context.Context, appName, domain string, extraArgs ...string)

UnmapRoute runs the unmap-route command.

func (*Kf) UnsetEnv

func (k *Kf) UnsetEnv(ctx context.Context, appName, name string)

UnsetEnv unsets the environment variable for an app.

func (*Kf) UpdateQuota

func (k *Kf) UpdateQuota(ctx context.Context, quotaName string, extraArgs ...string) ([]string, error)

UpdateQuota updates a quota.

func (*Kf) VcapServices

func (k *Kf) VcapServices(ctx context.Context, extraArgs ...string) []string

VcapServices runs the vcap-services command.

type KfTest

type KfTest func(ctx context.Context, t *testing.T, kf *Kf)

KfTest is a test ran by RunKfTest.

type KfTestConfig

type KfTestConfig struct {
	Args []string
	Env  map[string]string
}

KfTestConfig is a configuration for a Kf Test.

type KfTestOutput

type KfTestOutput struct {
	Stdout io.Reader
	Stderr io.Reader
	Stdin  io.Writer
	Done   <-chan struct{}
}

KfTestOutput is the output from `kf`. Note, this output is while kf is running.

type Reactable

type Reactable interface {
	AddReactor(verb, resource string, reaction testing.ReactionFunc)
}

type TestApiServer

type TestApiServer interface {
	// Get retrieves the object by its kind, namespace and name.
	Get(gvr schema.GroupVersionResource, ns, name string) (runtime.Object, error)

	// Create adds an object in the specified namespace.
	Create(gvr schema.GroupVersionResource, ns string, obj runtime.Object) (runtime.Object, error)

	// Update updates an existing object in the specified namespace.
	Update(gvr schema.GroupVersionResource, ns string, obj runtime.Object) (runtime.Object, error)

	// List retrieves all objects of a given kind in the given namespace.
	List(gvr schema.GroupVersionResource, ns string, gvk schema.GroupVersionKind, labelSelector labels.Selector) (runtime.Object, error)

	// Delete deletes an existing object.
	Delete(gvr schema.GroupVersionResource, ns, name string) error
}

Jump to

Keyboard shortcuts

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