github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/metricsdebug/export_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package metricsdebug 5 6 import ( 7 "errors" 8 "time" 9 10 "github.com/juju/juju/apiserver/params" 11 "github.com/juju/juju/cmd/modelcmd" 12 ) 13 14 var ( 15 NewClient = &newClient 16 NewRunClient = &newRunClient 17 ) 18 19 // NewRunClientFnc returns a function that returns a struct that implements the 20 // runClient interface. This function can be used to patch the NewRunClient 21 // variable in tests. 22 func NewRunClientFnc(client runClient) func(modelcmd.ModelCommandBase) (runClient, error) { 23 return func(_ modelcmd.ModelCommandBase) (runClient, error) { 24 return client, nil 25 } 26 } 27 28 func PatchGetActionResult(patchValue func(interface{}, interface{}), actions map[string]params.ActionResult) { 29 patchValue(&getActionResult, func(_ runClient, id string, _ *time.Timer) (params.ActionResult, error) { 30 if res, ok := actions[id]; ok { 31 return res, nil 32 } 33 return params.ActionResult{}, errors.New("plm") 34 }) 35 }