github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/api/backups/export_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups 5 6 import ( 7 "github.com/juju/juju/api/base" 8 ) 9 10 // ExposeFacade returns the client's underlying FacadeCaller. 11 func ExposeFacade(c *Client) base.FacadeCaller { 12 return c.facade 13 } 14 15 // SetHTTP sets the HTTP caller on the client. 16 func SetHTTP(c *Client, http httpClient) { 17 c.http = http 18 } 19 20 // PatchClientFacadeCall changes the internal FacadeCaller to one that lets 21 // you mock out the FacadeCall method. The function returned by 22 // PatchClientFacadeCall is a cleanup function that returns the client to its 23 // original state. 24 func PatchClientFacadeCall(c *Client, mockCall func(request string, params interface{}, response interface{}) error) func() { 25 orig := c.facade 26 c.facade = &resultCaller{mockCall} 27 return func() { 28 c.facade = orig 29 } 30 } 31 32 // PatchClientFacadeCall changes the internal FacadeCaller to one that lets 33 // you mock out the FacadeCall method. The function returned by 34 // PatchClientFacadeCall is a cleanup function that returns the client to its 35 // original state. 36 func PatchBaseFacadeCall(c *Client, mockCall func(request string, params interface{}, response interface{}) error) func() { 37 orig := c.baseFacade 38 c.baseFacade = &resultCaller{mockCall} 39 return func() { 40 c.facade = orig 41 } 42 } 43 44 type resultCaller struct { 45 mockCall func(request string, params interface{}, response interface{}) error 46 } 47 48 func (f *resultCaller) FacadeCall(request string, params, response interface{}) error { 49 return f.mockCall(request, params, response) 50 } 51 52 func (f *resultCaller) Name() string { 53 return "" 54 } 55 56 func (f *resultCaller) BestAPIVersion() int { 57 return 0 58 } 59 60 func (f *resultCaller) RawAPICaller() base.APICaller { 61 return nil 62 }