github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/juju/model/export_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package model 5 6 import ( 7 "time" 8 9 "github.com/juju/cmd" 10 11 "github.com/juju/juju/api" 12 "github.com/juju/juju/api/base" 13 "github.com/juju/juju/cmd/modelcmd" 14 "github.com/juju/juju/jujuclient" 15 ) 16 17 // NewConfigCommandForTest returns a configCommand with the api 18 // provided as specified. 19 func NewConfigCommandForTest(api configCommandAPI) cmd.Command { 20 cmd := &configCommand{ 21 api: api, 22 } 23 return modelcmd.Wrap(cmd) 24 } 25 26 // NewDefaultsCommandForTest returns a defaultsCommand with the api provided as specified. 27 func NewDefaultsCommandForTest(apiRoot api.Connection, dAPI defaultsCommandAPI, cAPI cloudAPI, store jujuclient.ClientStore) cmd.Command { 28 cmd := &defaultsCommand{ 29 newAPIRoot: func() (api.Connection, error) { return apiRoot, nil }, 30 newDefaultsAPI: func(caller base.APICallCloser) defaultsCommandAPI { return dAPI }, 31 newCloudAPI: func(caller base.APICallCloser) cloudAPI { return cAPI }, 32 } 33 cmd.SetClientStore(store) 34 return modelcmd.WrapController(cmd) 35 } 36 37 // NewRetryProvisioningCommandForTest returns a RetryProvisioningCommand with the api provided as specified. 38 func NewRetryProvisioningCommandForTest(api RetryProvisioningAPI) cmd.Command { 39 cmd := &retryProvisioningCommand{ 40 api: api, 41 } 42 return modelcmd.Wrap(cmd) 43 } 44 45 // NewShowCommandForTest returns a ShowCommand with the api provided as specified. 46 func NewShowCommandForTest(api ShowModelAPI, refreshFunc func(jujuclient.ClientStore, string) error, store jujuclient.ClientStore) cmd.Command { 47 cmd := &showModelCommand{api: api, RefreshModels: refreshFunc} 48 cmd.SetClientStore(store) 49 return modelcmd.Wrap(cmd) 50 } 51 52 // NewDumpCommandForTest returns a DumpCommand with the api provided as specified. 53 func NewDumpCommandForTest(api DumpModelAPI, store jujuclient.ClientStore) cmd.Command { 54 cmd := &dumpCommand{api: api} 55 cmd.SetClientStore(store) 56 return modelcmd.WrapController(cmd) 57 } 58 59 // NewDumpDBCommandForTest returns a DumpDBCommand with the api provided as specified. 60 func NewDumpDBCommandForTest(api DumpDBAPI, store jujuclient.ClientStore) cmd.Command { 61 cmd := &dumpDBCommand{api: api} 62 cmd.SetClientStore(store) 63 return modelcmd.WrapController(cmd) 64 } 65 66 // NewDestroyCommandForTest returns a DestroyCommand with the api provided as specified. 67 func NewDestroyCommandForTest( 68 api DestroyModelAPI, 69 refreshFunc func(jujuclient.ClientStore, string) error, store jujuclient.ClientStore, 70 sleepFunc func(time.Duration), 71 ) cmd.Command { 72 cmd := &destroyCommand{ 73 api: api, 74 RefreshModels: refreshFunc, 75 sleepFunc: sleepFunc, 76 } 77 cmd.SetClientStore(store) 78 return modelcmd.Wrap( 79 cmd, 80 modelcmd.WrapSkipDefaultModel, 81 modelcmd.WrapSkipModelFlags, 82 ) 83 } 84 85 type GrantCommand struct { 86 *grantCommand 87 } 88 89 type RevokeCommand struct { 90 *revokeCommand 91 } 92 93 // NewGrantCommandForTest returns a GrantCommand with the api provided as specified. 94 func NewGrantCommandForTest(api GrantModelAPI, store jujuclient.ClientStore) (cmd.Command, *GrantCommand) { 95 cmd := &grantCommand{ 96 api: api, 97 } 98 cmd.SetClientStore(store) 99 return modelcmd.WrapController(cmd), &GrantCommand{cmd} 100 } 101 102 // NewRevokeCommandForTest returns an revokeCommand with the api provided as specified. 103 func NewRevokeCommandForTest(api RevokeModelAPI, store jujuclient.ClientStore) (cmd.Command, *RevokeCommand) { 104 cmd := &revokeCommand{ 105 api: api, 106 } 107 cmd.SetClientStore(store) 108 return modelcmd.WrapController(cmd), &RevokeCommand{cmd} 109 }