github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/uniter/export_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package uniter 5 6 import ( 7 "fmt" 8 9 "gopkg.in/juju/names.v2" 10 11 "github.com/juju/juju/api/base" 12 "github.com/juju/juju/api/base/testing" 13 "github.com/juju/juju/api/common" 14 "github.com/juju/juju/apiserver/params" 15 ) 16 17 var ( 18 NewSettings = newSettings 19 ) 20 21 // PatchUnitResponse changes the internal FacadeCaller to one that lets you return 22 // canned results. The responseFunc will get the 'response' interface object, 23 // and can set attributes of it to fix the response to the caller. 24 // It can also return an error to have the FacadeCall return an error. The expected 25 // request is specified using the expectedRequest parameter. If the request name does 26 // not match, the function panics. 27 // The function returned by PatchResponses is a cleanup function that returns 28 // the client to its original state. 29 func PatchUnitResponse(p testing.Patcher, u *Unit, expectedRequest string, responseFunc func(interface{}) error) { 30 testing.PatchFacadeCall(p, &u.st.facade, func(request string, params, response interface{}) error { 31 if request != expectedRequest { 32 panic(fmt.Errorf("unexpected request %q received - expecting %q", request, expectedRequest)) 33 } 34 return responseFunc(response) 35 }) 36 } 37 38 func PatchUnitUpgradeSeriesFacade(u *Unit, facadeCaller base.FacadeCaller) { 39 u.st.UpgradeSeriesAPI = common.NewUpgradeSeriesAPI(facadeCaller, u.Tag()) 40 } 41 42 // CreateUnit creates uniter.Unit for tests. 43 func CreateUnit(st *State, tag names.UnitTag) *Unit { 44 return &Unit{ 45 st: st, 46 tag: tag, 47 life: params.Alive, 48 resolvedMode: params.ResolvedNone, 49 } 50 } 51 52 var NewStateV4 = newStateForVersionFn(4)