Пример #1
0
// PatchUnitResponse changes the internal FacadeCaller to one that lets you return
// canned results. The responseFunc will get the 'response' interface object,
// and can set attributes of it to fix the response to the caller.
// It can also return an error to have the FacadeCall return an error. The expected
// request is specified using the expectedRequest parameter. If the request name does
// not match, the function panics.
// The function returned by PatchResponses is a cleanup function that returns
// the client to its original state.
func PatchUnitResponse(p testing.Patcher, u *Unit, expectedRequest string, responseFunc func(interface{}) error) {
	testing.PatchFacadeCall(p, &u.st.facade, func(request string, params, response interface{}) error {
		if request != expectedRequest {
			panic(fmt.Errorf("unexpected request %q received - expecting %q", request, expectedRequest))
		}
		return responseFunc(response)
	})
}
Пример #2
0
// PatchFacadeCall patches the State's facade such that
// FacadeCall method calls are diverted to the provided
// function.
func PatchFacadeCall(p testing.Patcher, client *Client, f func(request string, params, response interface{}) error) {
	testing.PatchFacadeCall(p, &client.facade, f)
}
Пример #3
0
// PatchUnitFacadeCall changes the internal FacadeCaller to one that calls the provided request handler function.
func PatchUnitFacadeCall(p testing.Patcher, u *Unit, respFunc func(request string, params, response interface{}) error) {
	testing.PatchFacadeCall(p, &u.st.facade, respFunc)
}
Пример #4
0
// PatchResponses changes the internal FacadeCaller to one that lets you return
// canned results. The responseFunc will get the 'response' interface object,
// and can set attributes of it to fix the response to the caller.
// It can also return an error to have the FacadeCall return an error.
// The function returned by PatchResponses is a cleanup function that returns
// the client to its original state.
func PatchUnitResponse(p testing.Patcher, u *Unit, responseFunc func(interface{}) error) {
	testing.PatchFacadeCall(p, &u.st.facade, func(request string, params, response interface{}) error {
		return responseFunc(response)
	})
}
Пример #5
0
// PatchFacadeCall patches the State's facade such that
// FacadeCall method calls are diverted to the provided
// function.
func PatchFacadeCall(p testing.Patcher, st State, f func(request string, params, response interface{}) error) {
	st0 := st.(*state) // *state is the only implementation of State.
	testing.PatchFacadeCall(p, &st0.facade, f)
}
Пример #6
0
// PatchFacadeCall patches the State's facade such that
// FacadeCall method calls are diverted to the provided
// function.
func PatchFacadeCall(p testing.Patcher, st *State, f func(request string, params, response interface{}) error) {
	testing.PatchFacadeCall(p, &st.facade, f)
}
Пример #7
0
// PatchResponses changes the internal FacadeCaller to one that lets you return
// canned results. The responseFunc will get the 'response' interface object,
// and can set attributes of it to fix the response to the caller.
// It can also return an error to have the FacadeCall return an error.
// The function returned by PatchResponses is a cleanup function that returns
// the client to its original state.
func PatchResponses(p testing.Patcher, client *Client, responseFunc func(interface{}) error) {
	testing.PatchFacadeCall(p, &client.facade, func(request string, params, response interface{}) error {
		return responseFunc(response)
	})
}