github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/user/export_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package user 5 6 import ( 7 "github.com/juju/clock" 8 "github.com/juju/cmd" 9 10 "github.com/juju/juju/api" 11 "github.com/juju/juju/cmd/modelcmd" 12 "github.com/juju/juju/juju" 13 "github.com/juju/juju/jujuclient" 14 ) 15 16 var ( 17 APIOpen = &apiOpen 18 ListModels = &listModels 19 NewAPIConnection = &newAPIConnection 20 LoginClientStore = &loginClientStore 21 ) 22 23 const NoModelsMessage = noModelsMessage 24 25 type AddCommand struct { 26 *addCommand 27 } 28 29 type RemoveCommand struct { 30 *removeCommand 31 } 32 33 type ChangePasswordCommand struct { 34 *changePasswordCommand 35 } 36 37 type LoginCommand struct { 38 *loginCommand 39 } 40 41 type LogoutCommand struct { 42 *logoutCommand 43 } 44 45 type DisenableUserBase struct { 46 *disenableUserBase 47 } 48 49 func NewAddCommandForTest(api AddUserAPI, store jujuclient.ClientStore, modelAPI modelcmd.ModelAPI) (cmd.Command, *AddCommand) { 50 c := &addCommand{api: api} 51 c.SetClientStore(store) 52 c.SetModelAPI(modelAPI) 53 return modelcmd.WrapController(c), &AddCommand{c} 54 } 55 56 func NewRemoveCommandForTest(api RemoveUserAPI, store jujuclient.ClientStore) (cmd.Command, *RemoveCommand) { 57 c := &removeCommand{api: api} 58 c.SetClientStore(store) 59 return modelcmd.WrapController(c), &RemoveCommand{c} 60 } 61 62 func NewShowUserCommandForTest(api UserInfoAPI, store jujuclient.ClientStore) cmd.Command { 63 cmd := &infoCommand{infoCommandBase: infoCommandBase{ 64 clock: clock.WallClock, 65 api: api}} 66 cmd.SetClientStore(store) 67 return modelcmd.WrapController(cmd) 68 } 69 70 // NewChangePasswordCommand returns a ChangePasswordCommand with the api 71 // and writer provided as specified. 72 func NewChangePasswordCommandForTest( 73 newAPIConnection func(juju.NewAPIConnectionParams) (api.Connection, error), 74 api ChangePasswordAPI, 75 store jujuclient.ClientStore, 76 ) (cmd.Command, *ChangePasswordCommand) { 77 c := &changePasswordCommand{ 78 newAPIConnection: newAPIConnection, 79 api: api, 80 } 81 c.SetClientStore(store) 82 return modelcmd.WrapController(c), &ChangePasswordCommand{c} 83 } 84 85 // NewLogoutCommand returns a LogoutCommand with the api 86 // and writer provided as specified. 87 func NewLogoutCommandForTest(store jujuclient.ClientStore) (cmd.Command, *LogoutCommand) { 88 c := &logoutCommand{} 89 c.SetClientStore(store) 90 return modelcmd.WrapController(c), &LogoutCommand{c} 91 } 92 93 // NewDisableCommand returns a DisableCommand with the api provided as 94 // specified. 95 func NewDisableCommandForTest(api disenableUserAPI, store jujuclient.ClientStore) (cmd.Command, *DisenableUserBase) { 96 c := &disableCommand{disenableUserBase{api: api}} 97 c.SetClientStore(store) 98 return modelcmd.WrapController(c), &DisenableUserBase{&c.disenableUserBase} 99 } 100 101 // NewEnableCommand returns a EnableCommand with the api provided as 102 // specified. 103 func NewEnableCommandForTest(api disenableUserAPI, store jujuclient.ClientStore) (cmd.Command, *DisenableUserBase) { 104 c := &enableCommand{disenableUserBase{api: api}} 105 c.SetClientStore(store) 106 return modelcmd.WrapController(c), &DisenableUserBase{&c.disenableUserBase} 107 } 108 109 // NewListCommand returns a ListCommand with the api provided as specified. 110 func NewListCommandForTest(api UserInfoAPI, modelAPI modelUsersAPI, store jujuclient.ClientStore, clock clock.Clock) cmd.Command { 111 c := &listCommand{ 112 infoCommandBase: infoCommandBase{ 113 clock: clock, 114 api: api, 115 }, 116 modelUserAPI: modelAPI, 117 } 118 c.SetClientStore(store) 119 return modelcmd.WrapController(c) 120 } 121 122 // NewWhoAmICommandForTest returns a whoAMI command with a mock store. 123 func NewWhoAmICommandForTest(store jujuclient.ClientStore) cmd.Command { 124 c := &whoAmICommand{store: store} 125 return c 126 }