github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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/api"
    11  	"github.com/juju/juju/apiserver/params"
    12  )
    13  
    14  var (
    15  	NewClient        = &newClient
    16  	NewRunClient     = &newRunClient
    17  	NewServiceClient = &newServiceClient
    18  	NewAPIConn       = &newAPIConn
    19  )
    20  
    21  // NewRunClientFnc returns a function that returns a struct that implements the
    22  // runClient interface. This function can be used to patch the NewRunClient
    23  // variable in tests.
    24  func NewRunClientFnc(client runClient) func(api.Connection) runClient {
    25  	return func(_ api.Connection) runClient {
    26  		return client
    27  	}
    28  }
    29  
    30  // NewServiceClientFnc returns a function that returns a struct that implements the
    31  // serviceClient interface. This function can be used to patch the NewServiceClient
    32  // variable in tests.
    33  func NewServiceClientFnc(client serviceClient) func(api.Connection) serviceClient {
    34  	return func(_ api.Connection) serviceClient {
    35  		return client
    36  	}
    37  }
    38  
    39  func PatchGetActionResult(patchValue func(interface{}, interface{}), actions map[string]params.ActionResult) {
    40  	patchValue(&getActionResult, func(_ runClient, id string, _ *time.Timer) (params.ActionResult, error) {
    41  		if res, ok := actions[id]; ok {
    42  			return res, nil
    43  		}
    44  		return params.ActionResult{}, errors.New("plm")
    45  	})
    46  }