github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/api/base/testing/patch.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	"github.com/juju/juju/api/base"
     8  )
     9  
    10  // PatchFacadeCall patches the provided FacadeCaller such
    11  // that the FacadeCall method calls are diverted to the
    12  // provided function.
    13  func PatchFacadeCall(p Patcher, caller *base.FacadeCaller, f func(request string, params, response interface{}) error) {
    14  	p.PatchValue(caller, &facadeWrapper{*caller, f})
    15  }
    16  
    17  type Patcher interface {
    18  	PatchValue(dest, value interface{})
    19  }
    20  
    21  type facadeWrapper struct {
    22  	base.FacadeCaller
    23  	facadeCall func(request string, params, response interface{}) error
    24  }
    25  
    26  func (f *facadeWrapper) FacadeCall(request string, params, response interface{}) error {
    27  	return f.facadeCall(request, params, response)
    28  }