github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/controller/export_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package controller
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"github.com/juju/utils/clock"
     9  
    10  	"github.com/juju/juju/api"
    11  	"github.com/juju/juju/cmd/modelcmd"
    12  	"github.com/juju/juju/jujuclient"
    13  )
    14  
    15  // NewListControllersCommandForTest returns a listControllersCommand with the clientstore provided
    16  // as specified.
    17  func NewListControllersCommandForTest(testStore jujuclient.ClientStore) *listControllersCommand {
    18  	return &listControllersCommand{
    19  		store: testStore,
    20  	}
    21  }
    22  
    23  // NewShowControllerCommandForTest returns a showControllerCommand with the clientstore provided
    24  // as specified.
    25  func NewShowControllerCommandForTest(testStore jujuclient.ClientStore) *showControllerCommand {
    26  	return &showControllerCommand{
    27  		store: testStore,
    28  	}
    29  }
    30  
    31  type CreateModelCommand struct {
    32  	*createModelCommand
    33  }
    34  
    35  // NewCreateModelCommandForTest returns a CreateModelCommand with
    36  // the api provided as specified.
    37  func NewCreateModelCommandForTest(
    38  	api CreateModelAPI,
    39  	store jujuclient.ClientStore,
    40  	credentialStore jujuclient.CredentialStore,
    41  ) (cmd.Command, *CreateModelCommand) {
    42  	c := &createModelCommand{
    43  		api:             api,
    44  		credentialStore: credentialStore,
    45  	}
    46  	c.SetClientStore(store)
    47  	return modelcmd.WrapController(c), &CreateModelCommand{c}
    48  }
    49  
    50  // NewListModelsCommandForTest returns a ListModelsCommand with the API
    51  // and userCreds provided as specified.
    52  func NewListModelsCommandForTest(modelAPI ModelManagerAPI, sysAPI ModelsSysAPI, store jujuclient.ClientStore) cmd.Command {
    53  	c := &modelsCommand{
    54  		modelAPI: modelAPI,
    55  		sysAPI:   sysAPI,
    56  	}
    57  	c.SetClientStore(store)
    58  	return modelcmd.WrapController(c)
    59  }
    60  
    61  // NewRegisterCommandForTest returns a RegisterCommand with the function used
    62  // to open the API connection mocked out.
    63  func NewRegisterCommandForTest(apiOpen api.OpenFunc, refreshModels func(jujuclient.ClientStore, string, string) error, store jujuclient.ClientStore) *registerCommand {
    64  	return &registerCommand{apiOpen: apiOpen, refreshModels: refreshModels, store: store}
    65  }
    66  
    67  // NewRemoveBlocksCommandForTest returns a RemoveBlocksCommand with the
    68  // function used to open the API connection mocked out.
    69  func NewRemoveBlocksCommandForTest(api removeBlocksAPI, store jujuclient.ClientStore) cmd.Command {
    70  	c := &removeBlocksCommand{
    71  		api: api,
    72  	}
    73  	c.SetClientStore(store)
    74  	return modelcmd.WrapController(c)
    75  }
    76  
    77  // NewDestroyCommandForTest returns a DestroyCommand with the controller and
    78  // client endpoints mocked out.
    79  func NewDestroyCommandForTest(
    80  	api destroyControllerAPI,
    81  	clientapi destroyClientAPI,
    82  	store jujuclient.ClientStore,
    83  	apierr error,
    84  ) cmd.Command {
    85  	cmd := &destroyCommand{
    86  		destroyCommandBase: destroyCommandBase{
    87  			api:       api,
    88  			clientapi: clientapi,
    89  			apierr:    apierr,
    90  		},
    91  	}
    92  	cmd.SetClientStore(store)
    93  	return modelcmd.WrapController(
    94  		cmd,
    95  		modelcmd.ControllerSkipFlags,
    96  		modelcmd.ControllerSkipDefault,
    97  	)
    98  }
    99  
   100  // NewKillCommandForTest returns a killCommand with the controller and client
   101  // endpoints mocked out.
   102  func NewKillCommandForTest(
   103  	api destroyControllerAPI,
   104  	clientapi destroyClientAPI,
   105  	store jujuclient.ClientStore,
   106  	apierr error,
   107  	clock clock.Clock,
   108  	apiOpen modelcmd.APIOpener,
   109  ) cmd.Command {
   110  	kill := &killCommand{
   111  		destroyCommandBase: destroyCommandBase{
   112  			api:       api,
   113  			clientapi: clientapi,
   114  			apierr:    apierr,
   115  		},
   116  	}
   117  	kill.SetClientStore(store)
   118  	return wrapKillCommand(kill, apiOpen, clock)
   119  }
   120  
   121  // NewListBlocksCommandForTest returns a ListBlocksCommand with the controller
   122  // endpoint mocked out.
   123  func NewListBlocksCommandForTest(api listBlocksAPI, apierr error, store jujuclient.ClientStore) cmd.Command {
   124  	c := &listBlocksCommand{
   125  		api:    api,
   126  		apierr: apierr,
   127  	}
   128  	c.SetClientStore(store)
   129  	return modelcmd.WrapController(c)
   130  }
   131  
   132  type CtrData ctrData
   133  type ModelData modelData
   134  
   135  func FmtCtrStatus(data CtrData) string {
   136  	return fmtCtrStatus(ctrData(data))
   137  }
   138  
   139  func FmtModelStatus(data ModelData) string {
   140  	return fmtModelStatus(modelData(data))
   141  }
   142  
   143  func NewData(api destroyControllerAPI, ctrUUID string) (ctrData, []modelData, error) {
   144  	return newData(api, ctrUUID)
   145  }