github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/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/names" 9 10 "github.com/juju/juju/api/base/testing" 11 "github.com/juju/juju/apiserver/params" 12 ) 13 14 var ( 15 NewSettings = newSettings 16 NewStateV0 = newStateV0 17 NewStateV1 = newStateV1 18 ) 19 20 // PatchResponses changes the internal FacadeCaller to one that lets you return 21 // canned results. The responseFunc will get the 'response' interface object, 22 // and can set attributes of it to fix the response to the caller. 23 // It can also return an error to have the FacadeCall return an error. The expected 24 // request is specified using the expectedRequest parameter. If the request name does 25 // not match, the function panics. 26 // The function returned by PatchResponses is a cleanup function that returns 27 // the client to its original state. 28 func PatchUnitResponse(p testing.Patcher, u *Unit, expectedRequest string, responseFunc func(interface{}) error) { 29 testing.PatchFacadeCall(p, &u.st.facade, func(request string, params, response interface{}) error { 30 if request != expectedRequest { 31 panic(fmt.Errorf("unexpected request %q received - expecting %q", request, expectedRequest)) 32 } 33 return responseFunc(response) 34 }) 35 } 36 37 // PatchUnitFacadeCall changes the internal FacadeCaller to one that calls the provided request handler function. 38 func PatchUnitFacadeCall(p testing.Patcher, u *Unit, respFunc func(request string, params, response interface{}) error) { 39 testing.PatchFacadeCall(p, &u.st.facade, respFunc) 40 } 41 42 // CreateUnit creates uniter.Unit for tests. 43 func CreateUnit(st *State, tag names.UnitTag) *Unit { 44 return &Unit{st, tag, params.Alive} 45 }