github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/application/export_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package application 5 6 import ( 7 "github.com/juju/cmd" 8 "gopkg.in/juju/charmrepo.v2-unstable/csclient" 9 "gopkg.in/macaroon-bakery.v1/httpbakery" 10 11 "github.com/juju/juju/api" 12 "github.com/juju/juju/cmd/modelcmd" 13 "github.com/juju/juju/jujuclient" 14 "github.com/juju/juju/resource/resourceadapters" 15 ) 16 17 func NewUpgradeCharmCommandForTest( 18 store jujuclient.ClientStore, 19 apiOpener modelcmd.APIOpener, 20 deployResources resourceadapters.DeployResourcesFunc, 21 resolveCharm ResolveCharmFunc, 22 newCharmAdder NewCharmAdderFunc, 23 newCharmClient func(api.Connection) CharmClient, 24 newCharmUpgradeClient func(api.Connection) CharmUpgradeClient, 25 newModelConfigGetter func(api.Connection) ModelConfigGetter, 26 newResourceLister func(api.Connection) (ResourceLister, error), 27 ) cmd.Command { 28 cmd := &upgradeCharmCommand{ 29 DeployResources: deployResources, 30 ResolveCharm: resolveCharm, 31 NewCharmAdder: newCharmAdder, 32 NewCharmClient: newCharmClient, 33 NewCharmUpgradeClient: newCharmUpgradeClient, 34 NewModelConfigGetter: newModelConfigGetter, 35 NewResourceLister: newResourceLister, 36 } 37 cmd.SetClientStore(store) 38 cmd.SetAPIOpener(apiOpener) 39 return modelcmd.Wrap(cmd) 40 } 41 42 // NewConfigCommandForTest returns a SetCommand with the api provided as specified. 43 func NewConfigCommandForTest(api configCommandAPI) cmd.Command { 44 return modelcmd.Wrap(&configCommand{ 45 api: api, 46 }) 47 } 48 49 // NewAddUnitCommandForTest returns an AddUnitCommand with the api provided as specified. 50 func NewAddUnitCommandForTest(api serviceAddUnitAPI) cmd.Command { 51 return modelcmd.Wrap(&addUnitCommand{ 52 api: api, 53 }) 54 } 55 56 // NewAddRelationCommandForTest returns an AddRelationCommand with the api provided as specified. 57 func NewAddRelationCommandForTest(api ApplicationAddRelationAPI) cmd.Command { 58 cmd := &addRelationCommand{newAPIFunc: func() (ApplicationAddRelationAPI, error) { 59 return api, nil 60 }} 61 return modelcmd.Wrap(cmd) 62 } 63 64 // NewRemoveRelationCommandForTest returns an RemoveRelationCommand with the api provided as specified. 65 func NewRemoveRelationCommandForTest(api ApplicationDestroyRelationAPI) cmd.Command { 66 cmd := &removeRelationCommand{newAPIFunc: func() (ApplicationDestroyRelationAPI, error) { 67 return api, nil 68 }} 69 return modelcmd.Wrap(cmd) 70 } 71 72 type Patcher interface { 73 PatchValue(dest, value interface{}) 74 } 75 76 func PatchNewCharmStoreClient(s Patcher, url string) { 77 s.PatchValue(&newCharmStoreClient, func(bakeryClient *httpbakery.Client) *csclient.Client { 78 return csclient.New(csclient.Params{ 79 URL: url, 80 BakeryClient: bakeryClient, 81 }) 82 }) 83 }