fake

package
Version: v3.7.2+incompatible Latest Latest
Warning

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

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

Documentation

Overview

Package fake contains fake implementations of each of the CF broker APIs. They are all basic, in-memory implementations and are intended to be used in unit tests only

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInstanceNotFound is returned by the fake client when an instance was expected in its
	// internal storage but it wasn't found
	ErrInstanceNotFound = errors.New("instance not found")
	// ErrInstanceAlreadyExists is returned by the fake client when an instance was found in
	// internal storage but it wasn't expected
	ErrInstanceAlreadyExists = errors.New("instance already exists")
	// ErrBindingNotFound is returned by the fake client when a binding was expected in internal
	// storage but it wasn't found
	ErrBindingNotFound = errors.New("binding not found")
	// ErrBindingAlreadyExists is returned by the fake client when a binding was found in internal
	// storage but it wasn't expected
	ErrBindingAlreadyExists = errors.New("binding already exists")
)

Functions

func BindingsMapKey

func BindingsMapKey(instanceID, bindingID string) string

BindingsMapKey constructs the key used for bindings given a Service ID and a Binding ID

func NewClientFunc

func NewClientFunc(
	catCl *CatalogClient,
	instCl *InstanceClient,
	bindCl *BindingClient,
) func(name, url, username, password string) brokerapi.BrokerClient

NewClientFunc returns a function suitable for creating a new BrokerClient from a given Broker object. The returned function is suitable for passing as a callback to code that needs to create clients on-demand

Types

type BindingClient

type BindingClient struct {
	Bindings        map[string]*brokerapi.ServiceBinding
	BindingRequests map[string]*brokerapi.BindingRequest
	CreateCreds     brokerapi.Credential
	CreateErr       error
	DeleteErr       error
}

BindingClient implements a fake CF binding API client

func NewBindingClient

func NewBindingClient() *BindingClient

NewBindingClient creates a new empty binding client, ready for use

func (*BindingClient) CreateServiceBinding

func (b *BindingClient) CreateServiceBinding(
	instanceID,
	bindingID string,
	req *brokerapi.BindingRequest,
) (*brokerapi.CreateServiceBindingResponse, error)

CreateServiceBinding returns b.CreateErr if it was non-nil. Otherwise, returns ErrBindingAlreadyExists if the IDs already existed in b.Bindings. If they didn't already exist, adds the IDs to b.Bindings and returns a new CreateServiceBindingResponse with b.CreateCreds in it

func (*BindingClient) DeleteServiceBinding

func (b *BindingClient) DeleteServiceBinding(instanceID, bindingID, serviceID, planID string) error

DeleteServiceBinding returns b.DeleteErr if it was non-nil. Otherwise, if the binding associated with the given IDs didn't exist, returns ErrBindingNotFound. If it did exist, removes it and returns nil

type CatalogClient

type CatalogClient struct {
	RetCatalog *brokerapi.Catalog
	RetErr     error
}

CatalogClient implements a fake CF catalog API client

func (*CatalogClient) GetCatalog

func (c *CatalogClient) GetCatalog() (*brokerapi.Catalog, error)

GetCatalog just returns c.RetCatalog and c.RetErr

type Client

type Client struct {
	*CatalogClient
	*InstanceClient
	*BindingClient
}

Client implements a fake (./pkg/brokerapi).BrokerClient. The implementation is 100% in-memory and is useful for unit testing. None of the methods in this client are concurrency-safe.

See the (./pkg/controller).TestCreateServiceInstanceHelper unit test for example usage of this client

type InstanceClient

type InstanceClient struct {
	Instances                     map[string]*brokerapi.ServiceInstance
	ResponseCode                  int
	Operation                     string
	DashboardURL                  string
	LastOperationResponse         *brokerapi.LastOperationResponse
	DeleteServiceInstanceResponse *brokerapi.DeleteServiceInstanceResponse
	CreateErr                     error
	UpdateErr                     error
	DeleteErr                     error
	PollErr                       error
}

InstanceClient implements a fake CF instance API client

func NewInstanceClient

func NewInstanceClient() *InstanceClient

NewInstanceClient creates a new empty instance client ready for use

func (*InstanceClient) CreateServiceInstance

CreateServiceInstance returns i.CreateErr if non-nil. If it is nil, checks if id already exists in i.Instances and returns http.StatusConfict and ErrInstanceAlreadyExists if so. If not, converts req to a ServiceInstance and adds it to i.Instances

func (*InstanceClient) DeleteServiceInstance

DeleteServiceInstance returns i.DeleteErr if it was non-nil. Otherwise returns ErrInstanceNotFound if id didn't already exist in i.Instances. If it it did already exist, removes i.Instances[id] from the map and returns nil

func (*InstanceClient) PollServiceInstance

PollServiceInstance returns i.PollErr if it was non-nil. Otherwise returns i.LastOperationResponse

func (*InstanceClient) UpdateServiceInstance

UpdateServiceInstance returns i.UpdateErr if it was non-nil. Otherwise, returns ErrInstanceNotFound if id already exists in i.Instances. If it didn't exist, converts req into a ServiceInstance, adds it to i.Instances and returns it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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