util

package
v0.0.0-...-b80afe7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package util provides common test utility functions.

Index

Constants

View Source
const (

	// QueryServiceID is the service ID identifier used in a query.
	QueryServiceID = "service_id"

	// QueryPlanID is the plan ID identifier used in a query.
	QueryPlanID = "plan_id"

	// QueryOperation is the operation ID identifier used in a query.
	QueryOperation = "operation"
)
View Source
const (
	// CA is the CA for the server certificate.
	CA = `` /* 1203-byte string literal not displayed */

	// Cert is a valid for "DNS:localhost" until 2022-05-26.
	Cert = `` /* 1244-byte string literal not displayed */

	// Key is the private key for cert.
	Key = `` /* 1703-byte string literal not displayed */

	// Token is the default OAuth bearer token.
	Token = "HeMan"

	// Namespace is the default namespace, that isn't default.
	Namespace = "Skeletor"
)

Variables

View Source
var (

	// DefaultBrokerConfig is a minimal service broker config to allow initialization.
	DefaultBrokerConfig = &v1.ServiceBrokerConfig{
		ObjectMeta: metav1.ObjectMeta{
			Name:      "couchbase-service-broker",
			Namespace: Namespace,
		},
	}
)

Functions

func Assert

func Assert(t *testing.T, condition bool)

Assert asserts a condition holds, causing test failure if it doesn't.

func CreateServiceInstanceQuery

func CreateServiceInstanceQuery() *url.Values

CreateServiceInstanceQuery creates a query string for use with the service instance creation.

func DefaultClient

func DefaultClient() (*http.Client, error)

DefaultClient creates a HTTP client for use against the service broker. It applies known good configuration to provide connectivity with the broker for the common case.

func DefaultRequest

func DefaultRequest(method, path string) (*http.Request, error)

DefaultRequest creates a HTTP request object for the requested method on a path. It applies known good configuration to provide connectivity with the broker for the common case.

func DefaultRequestWithBody

func DefaultRequestWithBody(method, path string, body io.Reader) (*http.Request, error)

DefaultRequestWithBody creates a HTTP request object for the requested method on a path. It applies known good configuration to provide connectivity with the broker for the common case.

func Delete

func Delete(path string, statusCode int, response interface{}) error

Delete does a DELETE API call and expects a certain response.

func DeleteAndError

func DeleteAndError(path string, statusCode int, apiError api.ErrorType) error

DeleteAndError does a DELETE API call and expects a certain response with a valid JSON error.

func DeleteServiceBindingQuery

func DeleteServiceBindingQuery(req *api.CreateServiceBindingRequest) *url.Values

DeleteServiceBindingQuery creates a query string for use with the service binding deletion API. It is generated from the original service binding creation request.

func DeleteServiceInstanceQuery

func DeleteServiceInstanceQuery(req *api.CreateServiceInstanceRequest) *url.Values

DeleteServiceInstanceQuery creates a query string for use with the service instance deletion API. It is generated from the original service instance creation request.

func DoRequest

func DoRequest(client *http.Client, request *http.Request) (*http.Response, error)

DoRequest performs a requests against the broker API with the provided client. This call will cause test failure if the network transport fails.

func Get

func Get(path string, statusCode int, response interface{}) error

Get does a GET API call and expects a certain response.

func GetAndError

func GetAndError(path string, statusCode int, apiError api.ErrorType) error

GetAndError does a GET API call and expects a certain response with a valid JSON error.

func MatchHeader

func MatchHeader(response *http.Response, name, value string) error

MatchHeader checks if the header exists with the specified value.

func MustBasicRequest

func MustBasicRequest(t *testing.T, method, path string) *http.Request

MustBasicRequest creates a HTTP request object for the requested method on a path. It applies no additional headers.

func MustCreateServiceBinding

func MustCreateServiceBinding(t *testing.T, instance, binding string, req *api.CreateServiceBindingRequest)

MustCreateServiceBinding wraps up service binding creation.

func MustCreateServiceBrokerConfig

func MustCreateServiceBrokerConfig(t *testing.T, clients client.Clients, config *v1.ServiceBrokerConfig)

MustCreateServiceBrokerConfig creates the service broker configuration file with a user specified one.

func MustCreateServiceInstance

func MustCreateServiceInstance(t *testing.T, name string, req *api.CreateServiceInstanceRequest) *api.CreateServiceInstanceResponse

MustCreateServiceInstance wraps up service instance creation.

func MustCreateServiceInstanceSuccessfully

func MustCreateServiceInstanceSuccessfully(t *testing.T, name string, req *api.CreateServiceInstanceRequest)

MustCreateServiceInstanceSuccessfully wraps up service instance creation and polling.

func MustDefaultClient

func MustDefaultClient(t *testing.T) *http.Client

MustDefaultClient creates a HTTP client for use against the service broker. It applies known good configuration to provide connectivity with the broker for the common case.

func MustDefaultRequest

func MustDefaultRequest(t *testing.T, method, path string) *http.Request

MustDefaultRequest creates a HTTP request object for the requested method on a path. It applies known good configuration to provide connectivity with the broker for the common case.

func MustDefaultRequestWithBody

func MustDefaultRequestWithBody(t *testing.T, method, path string, body io.Reader) *http.Request

MustDefaultRequestWithBody creates a HTTP request object for the requested method on a path. It applies known good configuration to provide connectivity with the broker for the common case.

func MustDelete

func MustDelete(t *testing.T, path string, statusCode int, response interface{})

MustDelete does a DELETE API call and expects a certain response.

func MustDeleteAndError

func MustDeleteAndError(t *testing.T, path string, statusCode int, apiError api.ErrorType)

MustDeleteAndError does a DELETE API call and expects a certain response with a valid JSON error.

func MustDeleteServiceBinding

func MustDeleteServiceBinding(t *testing.T, instance, binding string, req *api.CreateServiceBindingRequest)

MustDeleteServiceBinding wraps up service binding deletion.

func MustDeleteServiceBrokerConfig

func MustDeleteServiceBrokerConfig(t *testing.T, clients client.Clients)

MustDeleteServiceBrokerConfig deletes the service broker configuration file.

func MustDeleteServiceInstance

func MustDeleteServiceInstance(t *testing.T, name string, req *api.CreateServiceInstanceRequest) *api.CreateServiceInstanceResponse

MustDeleteServiceInstance wraps up service instance deletion.

func MustDeleteServiceInstanceSuccessfully

func MustDeleteServiceInstanceSuccessfully(t *testing.T, name string, req *api.CreateServiceInstanceRequest)

MustDeleteServiceInstanceSuccessfully wraps up service instance deletion and polling.

func MustDoRequest

func MustDoRequest(t *testing.T, client *http.Client, request *http.Request) *http.Response

MustDoRequest performs a requests against the broker API with the provided client. This call will cause test failure if the network transport fails.

func MustGet

func MustGet(t *testing.T, path string, statusCode int, response interface{})

MustGet does a GET API call and expects a certain response.

func MustGetAndError

func MustGetAndError(t *testing.T, path string, statusCode int, apiError api.ErrorType)

MustGetAndError does a GET API call and expects a certain response with a valid JSON error.

func MustGetRegistryEntry

func MustGetRegistryEntry(t *testing.T, clients client.Clients, rt registry.Type, name string) *corev1.Secret

MustGetRegistryEntry returns the registry entry for a service instance.

func MustHaveRegistryEntriesTLS

func MustHaveRegistryEntriesTLS(t *testing.T, entry *corev1.Secret, key, cert registry.Key)

MustHaveRegistryEntriesTLS checks that the requested entries corresponding to a certificate and key pair exist and they are valid.

func MustHaveRegistryEntriesTLSAndVerify

func MustHaveRegistryEntriesTLSAndVerify(t *testing.T, entry *corev1.Secret, caCert, key, cert registry.Key, usage x509.ExtKeyUsage)

MustHaveRegistryEntriesTLSAndVerify checks that the requested entries corresponding to a certificate and key pair exist and they are valid against a CA.

func MustHaveRegistryEntryPassword

func MustHaveRegistryEntryPassword(t *testing.T, entry *corev1.Secret, key registry.Key, length int, dictionary string)

MustHaveRegistryEntryPassword checks a registry entry exists and is valid for a password.

func MustHaveRegistryEntryWithValue

func MustHaveRegistryEntryWithValue(t *testing.T, entry *corev1.Secret, key registry.Key, value string)

MustHaveRegistryEntryWithValue checks a registry entry exists.

func MustNotDoRequest

func MustNotDoRequest(t *testing.T, client *http.Client, request *http.Request)

MustNotDoRequest performs a requests against the broker API with the provided client. This call will cause test failure if the network transport succeeds.

func MustNotHaveRegistryEntry

func MustNotHaveRegistryEntry(t *testing.T, entry *corev1.Secret, key registry.Key)

MustNotHaveRegistryEntry checks a registry entry doesn't exist.

func MustPatch

func MustPatch(t *testing.T, path string, statusCode int, request, response interface{})

MustPatch does a PATCH API call and expects a certain response.

func MustPatchAndError

func MustPatchAndError(t *testing.T, path string, statusCode int, request interface{}, apiError api.ErrorType)

MustPatchAndError does a PATCH API call and expects a certain response with a valid JSON error.

func MustPollServiceInstanceForCompletion

func MustPollServiceInstanceForCompletion(t *testing.T, name string, rsp *api.CreateServiceInstanceResponse)

MustPollServiceInstanceForCompletion wraps up service instance poll.

func MustPollServiceInstanceForDeletion

func MustPollServiceInstanceForDeletion(t *testing.T, name string, rsp *api.CreateServiceInstanceResponse)

MustPollServiceInstanceForDeletion wraps up polling for an aysnc deletion.

func MustPut

func MustPut(t *testing.T, path string, statusCode int, request, response interface{})

MustPut does a PUT API call and expects a certain response.

func MustPutAndError

func MustPutAndError(t *testing.T, path string, statusCode int, request interface{}, apiError api.ErrorType)

MustPutAndError does a PUT API call and expects a certain response with a valid JSON error.

func MustReplaceBrokerConfig

func MustReplaceBrokerConfig(t *testing.T, clients client.Clients, spec *v1.ServiceBrokerConfigSpec)

MustReplaceBrokerConfig updates the service broker configuration and waits for the broker to acquire the write lock and update the configuration to make it live.

func MustReplaceBrokerConfigWithInvalidCondition

func MustReplaceBrokerConfigWithInvalidCondition(t *testing.T, clients client.Clients, spec *v1.ServiceBrokerConfigSpec)

MustReplaceBrokerConfigWithInvalidCondition will updata the configuration and then ensure that the broker has registered it is invalid.

func MustResetDynamicClient

func MustResetDynamicClient(t *testing.T, clients client.Clients)

ResetDynamicClient deletes any objects created by template rendering. This simulates garbage collection when a registry item is deleted.

func MustUpdateBrokerConfig

func MustUpdateBrokerConfig(t *testing.T, clients client.Clients, callback func(*v1.ServiceBrokerConfig))

MustUpdateBrokerConfig updates the service broker configuration with a typesafe callback.

func MustUpdateServiceInstance

func MustUpdateServiceInstance(t *testing.T, name string, req *api.UpdateServiceInstanceRequest) *api.CreateServiceInstanceResponse

MustUpdateServiceInstance wraps up service instance creation.

func MustUpdateServiceInstanceSuccessfully

func MustUpdateServiceInstanceSuccessfully(t *testing.T, name string, req *api.UpdateServiceInstanceRequest)

MustUpdateServiceInstanceSuccessfully wraps up service instance update and polling.

func MustVerifyStatusCode

func MustVerifyStatusCode(t *testing.T, response *http.Response, statusCode int)

MustVerifyStatusCode verifies the HTTP status code is as expected. This call will cause test failure if the HTTP status code does not match.

func MustWaitFor

func MustWaitFor(t *testing.T, f util.WaitFunc, timeout time.Duration)

MustWaitFor waits until a condition is nil.

func NewClients

func NewClients() (client.Clients, error)

NewClients creates a new set of fake clients for use by testing.

func Patch

func Patch(path string, statusCode int, request, response interface{}) error

Patch does a PATCH API call and expects a certain response.

func PatchAndError

func PatchAndError(path string, statusCode int, request interface{}, apiError api.ErrorType) error

PatchAndError does a PATCH API call and expects a certain response with a valid JSON error.

func PollServiceInstanceQuery

func PollServiceInstanceQuery(req *api.CreateServiceInstanceRequest, rsp *api.CreateServiceInstanceResponse) *url.Values

PollServiceInstanceQuery creates a query string for use with the service instance polling API. It is generated from the original service instance creation request and the response containing the operation ID.

func Put

func Put(path string, statusCode int, request, response interface{}) error

Put does a PUT API call and expects a certain response.

func PutAndError

func PutAndError(path string, statusCode int, request interface{}, apiError api.ErrorType) error

PutAndError does a PUT API call and expects a certain response with a valid JSON error.

func ReadServiceInstanceQuery

func ReadServiceInstanceQuery(req *api.CreateServiceInstanceRequest) *url.Values

ReadServiceInstanceQuery creates a query string for use with the service instance get API. It is generated from the original service instance creation request.

func ResetClients

func ResetClients(clients client.Clients) error

ResetClients resets clients back to a pristine state. The kubernetes and dynamic clients have their own object caches, therefore objects created with the kubernetes client cannot be cleaned up using the dynamic client. This also has implications for the service broker as a whole. Clients are reset by just overwriting them, therefore at any one time only the top level clients interface is valid. Objects contained within must not be cached e.g. references to the kubernetes client for example.

func ServerRunning

func ServerRunning() error

ServerRunning is a wait function that checks the server is accepting TCP traffic, and responding with a good status to the readiness check endpoint.

func ServiceBindingURI

func ServiceBindingURI(instance, binding string, query *url.Values) string

ServiceBindingURI generates a URI (path + query) to operate on a service binding.

func ServiceInstancePollURI

func ServiceInstancePollURI(instance string, query *url.Values) string

ServiceInstancePollURI generates a URI (path + query) to operate on a service instance polling.

func ServiceInstanceURI

func ServiceInstanceURI(instance string, query *url.Values) string

ServiceInstanceURI generates a URI (path + query) to operate on a service instance.

func UpdateServiceInstanceQuery

func UpdateServiceInstanceQuery() *url.Values

UpdateServiceInstanceQuery creates a query string for use with the service instance update.

func VerifyStatusCode

func VerifyStatusCode(response *http.Response, statusCode int) error

VerifyStatusCode verifies the HTTP status code is as expected. This call will cause test failure if the HTTP status code does not match.

func WaitFor

func WaitFor(f util.WaitFunc, timeout time.Duration) error

WaitFor waits until a condition is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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