testing

package
v0.0.0-...-8ff1004 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APICallerWithBakery

func APICallerWithBakery(callerFunc APICallerFunc, dischargeAcquirer httpbakery.DischargeAcquirer) *apiCallerWithBakery

APICallerWithBakery returns an api caller with a bakery client which uses the specified discharge acquirer.

func NotifyingAPICaller

func NotifyingAPICaller(c *gc.C, called chan<- struct{}, caller base.APICaller) base.APICaller

NotifyingAPICaller returns an APICaller implementation which sends a message on the given channel every time it receives a call.

func PatchFacadeCall

func PatchFacadeCall(p Patcher, caller *base.FacadeCaller, f func(request string, params, response interface{}) error)

PatchFacadeCall patches the provided FacadeCaller such that the FacadeCall method calls are diverted to the provided function.

Types

type APICall

type APICall struct {
	// If Check is non-nil, all other fields will be ignored and Check
	// will be called to check the call.
	Check func(objType string, version int, id, request string, params, response interface{}) error

	// Facade holds the expected call facade. If it's empty,
	// any facade will be accepted.
	Facade string

	// Version holds the expected call version. If it's zero,
	// any version will be accepted unless VersionIsZero is true.
	Version int

	// VersionIsZero holds whether the version is expected to be zero.
	VersionIsZero bool

	// Id holds the expected call id. If it's empty, any id will be
	// accepted unless IdIsEmpty is true.
	Id string

	// IdIsEmpty holds whether the call id is expected to be empty.
	IdIsEmpty bool

	// Method holds the expected method.
	Method string

	// Args holds the expected value of the call's argument.
	Args interface{}

	// Results is assigned to the result parameter of the call on return.
	Results interface{}

	// Error is returned from the call.
	Error error
}

APICall describes an expected API call.

type APICallerFunc

type APICallerFunc func(objType string, version int, id, request string, params, response interface{}) error

APICallerFunc is a function type that implements APICaller. The only method that actually does anything is APICall itself which calls the function. The other methods are just stubs.

func (APICallerFunc) APICall

func (f APICallerFunc) APICall(objType string, version int, id, request string, params, response interface{}) error

func (APICallerFunc) BakeryClient

func (APICallerFunc) BakeryClient() *httpbakery.Client

func (APICallerFunc) BestFacadeVersion

func (APICallerFunc) BestFacadeVersion(facade string) int

func (APICallerFunc) Close

func (APICallerFunc) Close() error

func (APICallerFunc) ConnectControllerStream

func (APICallerFunc) ConnectControllerStream(path string, attrs url.Values, headers http.Header) (base.Stream, error)

func (APICallerFunc) ConnectStream

func (APICallerFunc) ConnectStream(path string, attrs url.Values) (base.Stream, error)

func (APICallerFunc) HTTPClient

func (APICallerFunc) HTTPClient() (*httprequest.Client, error)

func (APICallerFunc) ModelTag

func (APICallerFunc) ModelTag() (names.ModelTag, bool)

type BestVersionCaller

type BestVersionCaller struct {
	APICallerFunc
	BestVersion int
}

BestVersionCaller is an APICallerFunc that has a particular best version.

func (BestVersionCaller) BestFacadeVersion

func (c BestVersionCaller) BestFacadeVersion(facade string) int

type CallChecker

type CallChecker struct {
	APICallerFunc

	// CallCount records the current call count.
	CallCount int
}

CallChecker is an APICaller implementation that checks calls as they are made.

func APICallChecker

func APICallChecker(c *gc.C, calls ...APICall) *CallChecker

APICallChecker returns an APICaller implementation that checks API calls. Each element of calls corresponds to an expected API call. If more calls are made than there are elements, they will not be checked - check the value of the Count field to ensure that the expected number of calls have been made.

Note that the returned value is not thread-safe - do not use it if the client is making concurrent calls.

type Patcher

type Patcher interface {
	PatchValue(dest, value interface{})
}

type StubFacadeCaller

type StubFacadeCaller struct {
	// Stub is the raw stub used to track calls and errors.
	Stub *testing.Stub
	// These control the values returned by the stub's methods.
	FacadeCallFn         func(name string, params, response interface{}) error
	ReturnName           string
	ReturnBestAPIVersion int
	ReturnRawAPICaller   base.APICaller
}

StubFacadeCaller is a testing stub implementation of api/base.FacadeCaller.

func (*StubFacadeCaller) BestAPIVersion

func (s *StubFacadeCaller) BestAPIVersion() int

BestAPIVersion implements api/base.FacadeCaller.

func (*StubFacadeCaller) FacadeCall

func (s *StubFacadeCaller) FacadeCall(request string, params, response interface{}) error

FacadeCall implements api/base.FacadeCaller.

func (*StubFacadeCaller) Name

func (s *StubFacadeCaller) Name() string

Name implements api/base.FacadeCaller.

func (*StubFacadeCaller) RawAPICaller

func (s *StubFacadeCaller) RawAPICaller() base.APICaller

RawAPICaller implements api/base.FacadeCaller.

Jump to

Keyboard shortcuts

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