// NewDefaultsCommandForTest returns a defaultsCommand with the api provided as specified. func NewDefaultsCommandForTest(api defaultsCommandAPI, store jujuclient.ClientStore) cmd.Command { cmd := &defaultsCommand{ api: api, } cmd.SetClientStore(store) return modelcmd.WrapController(cmd) }
func NewListCommand() cmd.Command { return modelcmd.WrapController(&listCommand{ infoCommandBase: infoCommandBase{ clock: clock.WallClock, }, }) }
// NewGrantCommandForTest returns a GrantCommand with the api provided as specified. func NewGrantCommandForTest(api GrantModelAPI, store jujuclient.ClientStore) (cmd.Command, *GrantCommand) { cmd := &grantCommand{ api: api, } cmd.SetClientStore(store) return modelcmd.WrapController(cmd), &GrantCommand{cmd} }
func NewShowUserCommandForTest(api UserInfoAPI, store jujuclient.ClientStore) cmd.Command { cmd := &infoCommand{infoCommandBase: infoCommandBase{ clock: clock.WallClock, api: api}} cmd.SetClientStore(store) return modelcmd.WrapController(cmd) }
// NewEnableDestroyControllerCommandForTest returns a enableDestroyController with the // function used to open the API connection mocked out. func NewEnableDestroyControllerCommandForTest(api removeBlocksAPI, store jujuclient.ClientStore) cmd.Command { c := &enableDestroyController{ api: api, } c.SetClientStore(store) return modelcmd.WrapController(c) }
// NewRevokeCommandForTest returns an revokeCommand with the api provided as specified. func NewRevokeCommandForTest(api RevokeModelAPI, store jujuclient.ClientStore) (cmd.Command, *RevokeCommand) { cmd := &revokeCommand{ api: api, } cmd.SetClientStore(store) return modelcmd.WrapController(cmd), &RevokeCommand{cmd} }
// NewModelsCommandForTest returns a EnvironmentsCommand with the API // and userCreds provided as specified. func NewModelsCommandForTest(modelAPI ModelManagerAPI, sysAPI ModelsSysAPI, userCreds *configstore.APICredentials) cmd.Command { return modelcmd.WrapController(&environmentsCommand{ modelAPI: modelAPI, sysAPI: sysAPI, userCreds: userCreds, }) }
// NewCreateModelCommandForTest returns a CreateModelCommand with // the api provided as specified. func NewCreateModelCommandForTest(api CreateEnvironmentAPI, parser func(interface{}) (interface{}, error)) (cmd.Command, *CreateModelCommand) { c := &createModelCommand{ api: api, configParser: parser, } return modelcmd.WrapController(c), &CreateModelCommand{c} }
// NewChangePasswordCommand returns a ChangePasswordCommand with the api // and writer provided as specified. func NewChangePasswordCommandForTest(api ChangePasswordAPI, writer EnvironInfoCredsWriter) (cmd.Command, *ChangePasswordCommand) { c := &changePasswordCommand{ api: api, writer: writer, } return modelcmd.WrapController(c), &ChangePasswordCommand{c} }
func (s *MigrateSuite) runCommand(c *gc.C, args ...string) (*cmd.Context, error) { cmd := &migrateCommand{ api: s.api, } cmd.SetClientStore(s.store) return testing.RunCommand(c, modelcmd.WrapController(cmd), args...) }
func NewUpdateCredentialCommandForTest(testStore jujuclient.ClientStore, api credentialAPI) cmd.Command { c := &updateCredentialCommand{ api: api, } c.SetClientStore(testStore) return modelcmd.WrapController(c) }
// NewListBlocksCommandForTest returns a ListBlocksCommand with the controller // endpoint mocked out. func NewListBlocksCommandForTest(api listBlocksAPI, apierr error, store jujuclient.ClientStore) cmd.Command { c := &listBlocksCommand{ api: api, apierr: apierr, } c.SetClientStore(store) return modelcmd.WrapController(c) }
// NewListCommand returns a ListCommand with the api provided as specified. func NewListCommandForTest(api UserInfoAPI) cmd.Command { c := &listCommand{ infoCommandBase: infoCommandBase{ api: api, }, } return modelcmd.WrapController(c) }
// NewEnableCommand returns a EnableCommand with the api provided as // specified. func NewEnableCommandForTest(api disenableUserAPI) (cmd.Command, *DisenableUserBase) { c := &enableCommand{ disenableUserBase{ api: api, }, } return modelcmd.WrapController(c), &DisenableUserBase{&c.disenableUserBase} }
// NewUseModelCommandForTest returns a UseModelCommand with the // API and userCreds provided as specified. func NewUseModelCommandForTest(api UseModelAPI, userCreds *configstore.APICredentials, endpoint *configstore.APIEndpoint) (cmd.Command, *UseModelCommand) { c := &useModelCommand{ api: api, userCreds: userCreds, endpoint: endpoint, } return modelcmd.WrapController(c), &UseModelCommand{c} }
// NewListModelsCommandForTest returns a ListModelsCommand with the API // and userCreds provided as specified. func NewListModelsCommandForTest(modelAPI ModelManagerAPI, sysAPI ModelsSysAPI, store jujuclient.ClientStore) cmd.Command { c := &modelsCommand{ modelAPI: modelAPI, sysAPI: sysAPI, } c.SetClientStore(store) return modelcmd.WrapController(c) }
// NewLoginCommand returns a LoginCommand with the api // and writer provided as specified. func NewLoginCommandForTest( newLoginAPI func(juju.NewAPIConnectionParams) (LoginAPI, error), store jujuclient.ClientStore, ) (cmd.Command, *LoginCommand) { c := &loginCommand{newLoginAPI: newLoginAPI} c.SetClientStore(store) return modelcmd.WrapController(c), &LoginCommand{c} }
func initTestControllerCommand(c *gc.C, store jujuclient.ClientStore, args ...string) (cmd.Command, *testControllerCommand, error) { cmd := new(testControllerCommand) cmd.SetClientStore(store) wrapped := modelcmd.WrapController(cmd) if err := cmdtesting.InitCommand(wrapped, args); err != nil { return nil, nil, err } return wrapped, cmd, nil }
// NewDefaultsCommandForTest returns a defaultsCommand with the api provided as specified. func NewDefaultsCommandForTest(apiRoot api.Connection, dAPI defaultsCommandAPI, cAPI cloudAPI, store jujuclient.ClientStore) cmd.Command { cmd := &defaultsCommand{ newAPIRoot: func() (api.Connection, error) { return apiRoot, nil }, newDefaultsAPI: func(caller base.APICallCloser) defaultsCommandAPI { return dAPI }, newCloudAPI: func(caller base.APICallCloser) cloudAPI { return cAPI }, } cmd.SetClientStore(store) return modelcmd.WrapController(cmd) }
// NewAddModelCommand returns a command to add a model. func NewAddModelCommand() cmd.Command { return modelcmd.WrapController(&addModelCommand{ newAddModelAPI: func(caller base.APICallCloser) AddModelAPI { return modelmanager.NewClient(caller) }, newCloudAPI: func(caller base.APICallCloser) CloudAPI { return cloudapi.NewClient(caller) }, }) }
// NewListCommand returns a ListCommand with the api provided as specified. func NewListCommandForTest(api UserInfoAPI, modelAPI modelUsersAPI, store jujuclient.ClientStore, clock clock.Clock) cmd.Command { c := &listCommand{ infoCommandBase: infoCommandBase{ clock: clock, api: api, }, modelUserAPI: modelAPI, } c.SetClientStore(store) return modelcmd.WrapController(c) }
// NewLoginCommand returns a new cmd.Command to handle "juju login". func NewLoginCommand() cmd.Command { return modelcmd.WrapController(&loginCommand{ newLoginAPI: func(args juju.NewAPIConnectionParams) (LoginAPI, ConnectionAPI, error) { api, err := juju.NewAPIConnection(args) if err != nil { return nil, nil, errors.Trace(err) } return usermanager.NewClient(api), api, nil }, }) }
// NewDestroyCommand returns a command to destroy a controller. func NewDestroyCommand() cmd.Command { // Even though this command is all about destroying a controller we end up // needing environment endpoints so we can fall back to the client destroy // environment method. This shouldn't really matter in practice as the // user trying to take down the controller will need to have access to the // controller environment anyway. return modelcmd.WrapController( &destroyCommand{}, modelcmd.WrapControllerSkipControllerFlags, modelcmd.WrapControllerSkipDefaultController, ) }
// wrapKillCommand provides the common wrapping used by tests and // the default NewKillCommand above. func wrapKillCommand(kill *killCommand, apiOpen modelcmd.APIOpener, clock clock.Clock) cmd.Command { if apiOpen == nil { apiOpen = modelcmd.OpenFunc(kill.JujuCommandBase.NewAPIRoot) } openStrategy := modelcmd.NewTimeoutOpener(apiOpen, clock, 10*time.Second) return modelcmd.WrapController( kill, modelcmd.WrapControllerSkipControllerFlags, modelcmd.WrapControllerSkipDefaultController, modelcmd.WrapControllerAPIOpener(openStrategy), ) }
// NewChangePasswordCommand returns a ChangePasswordCommand with the api // and writer provided as specified. func NewChangePasswordCommandForTest( newAPIConnection func(juju.NewAPIConnectionParams) (api.Connection, error), api ChangePasswordAPI, store jujuclient.ClientStore, ) (cmd.Command, *ChangePasswordCommand) { c := &changePasswordCommand{ newAPIConnection: newAPIConnection, api: api, } c.SetClientStore(store) return modelcmd.WrapController(c), &ChangePasswordCommand{c} }
// NewDefaultsCommand wraps defaultsCommand with sane model settings. func NewDefaultsCommand() cmd.Command { defaultsCmd := &defaultsCommand{ newCloudAPI: func(caller base.APICallCloser) cloudAPI { return cloudapi.NewClient(caller) }, newDefaultsAPI: func(caller base.APICallCloser) defaultsCommandAPI { return modelmanager.NewClient(caller) }, } defaultsCmd.newAPIRoot = defaultsCmd.NewAPIRoot return modelcmd.WrapController(defaultsCmd) }
// NewAddModelCommandForTest returns a AddModelCommand with // the api provided as specified. func NewAddModelCommandForTest( api CreateModelAPI, store jujuclient.ClientStore, credentialStore jujuclient.CredentialStore, ) (cmd.Command, *AddModelCommand) { c := &addModelCommand{ api: api, credentialStore: credentialStore, } c.SetClientStore(store) return modelcmd.WrapController(c), &AddModelCommand{c} }
func newEnableHACommand() cmd.Command { haCommand := &enableHACommand{} haCommand.newHAClientFunc = func() (MakeHAClient, error) { root, err := haCommand.NewAPIRoot() if err != nil { return nil, errors.Annotate(err, "cannot get API connection") } // NewClient does not return an error, so we'll return nil return highavailability.NewClient(root), nil } return modelcmd.WrapController(haCommand) }
// NewAddModelCommandForTest returns a AddModelCommand with // the api provided as specified. func NewAddModelCommandForTest( apiRoot api.Connection, api AddModelAPI, cloudAPI CloudAPI, store jujuclient.ClientStore, ) (cmd.Command, *AddModelCommand) { c := &addModelCommand{ apiRoot: apiRoot, newAddModelAPI: func(caller base.APICallCloser) AddModelAPI { return api }, newCloudAPI: func(base.APICallCloser) CloudAPI { return cloudAPI }, } c.SetClientStore(store) return modelcmd.WrapController(c), &AddModelCommand{c} }
// NewDestroyCommandForTest returns a DestroyCommand with the controller and // client endpoints mocked out. func NewDestroyCommandForTest( api destroyControllerAPI, clientapi destroyClientAPI, store jujuclient.ClientStore, apierr error, ) cmd.Command { cmd := &destroyCommand{ destroyCommandBase: destroyCommandBase{ api: api, clientapi: clientapi, apierr: apierr, }, } cmd.SetClientStore(store) return modelcmd.WrapController( cmd, modelcmd.WrapControllerSkipControllerFlags, modelcmd.WrapControllerSkipDefaultController, ) }