github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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/cmd" 11 12 "github.com/juju/juju/api" 13 "github.com/juju/juju/apiserver/params" 14 "github.com/juju/juju/cmd/modelcmd" 15 "github.com/juju/juju/jujuclient/jujuclienttesting" 16 ) 17 18 var ( 19 NewClient = &newClient 20 NewRunClient = &newRunClient 21 NewAPIConn = &newAPIConn 22 ) 23 24 // NewRunClientFnc returns a function that returns a struct that implements the 25 // runClient interface. This function can be used to patch the NewRunClient 26 // variable in tests. 27 func NewRunClientFnc(client runClient) func(api.Connection) runClient { 28 return func(_ api.Connection) runClient { 29 return client 30 } 31 } 32 33 func PatchGetActionResult(patchValue func(interface{}, interface{}), actions map[string]params.ActionResult) { 34 patchValue(&getActionResult, func(_ runClient, id string, _ *time.Timer) (params.ActionResult, error) { 35 if res, ok := actions[id]; ok { 36 return res, nil 37 } 38 return params.ActionResult{}, errors.New("plm") 39 }) 40 } 41 42 func NewCollectMetricsCommandForTest() cmd.Command { 43 cmd := &collectMetricsCommand{} 44 cmd.SetClientStore(jujuclienttesting.MinimalStore()) 45 return modelcmd.Wrap(cmd) 46 } 47 48 func NewMetricsCommandForTest() cmd.Command { 49 cmd := &MetricsCommand{} 50 cmd.SetClientStore(jujuclienttesting.MinimalStore()) 51 return modelcmd.Wrap(cmd) 52 }