github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/api/uniter/export_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 package uniter 4 5 import ( 6 "fmt" 7 8 "github.com/juju/juju/api/base/testing" 9 ) 10 11 var ( 12 NewSettings = newSettings 13 NewStateV0 = newStateV0 14 NewStateV1 = newStateV1 15 ) 16 17 // PatchResponses changes the internal FacadeCaller to one that lets you return 18 // canned results. The responseFunc will get the 'response' interface object, 19 // and can set attributes of it to fix the response to the caller. 20 // It can also return an error to have the FacadeCall return an error. The expected 21 // request is specified using the expectedRequest parameter. If the request name does 22 // not match, the function panics. 23 // The function returned by PatchResponses is a cleanup function that returns 24 // the client to its original state. 25 func PatchUnitResponse(p testing.Patcher, u *Unit, expectedRequest string, responseFunc func(interface{}) error) { 26 testing.PatchFacadeCall(p, &u.st.facade, func(request string, params, response interface{}) error { 27 if request != expectedRequest { 28 panic(fmt.Errorf("unexpected request %q received - expecting %q", request, expectedRequest)) 29 } 30 return responseFunc(response) 31 }) 32 }