github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/cloud/export_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package cloud 5 6 import ( 7 "github.com/juju/cmd" 8 9 jujucloud "github.com/juju/juju/cloud" 10 "github.com/juju/juju/cmd/modelcmd" 11 "github.com/juju/juju/environs" 12 "github.com/juju/juju/environs/context" 13 sstesting "github.com/juju/juju/environs/simplestreams/testing" 14 "github.com/juju/juju/jujuclient" 15 ) 16 17 var ( 18 ShouldFinalizeCredential = shouldFinalizeCredential 19 ) 20 21 func NewAddCloudCommandForTest( 22 cloudMetadataStore CloudMetadataStore, 23 store jujuclient.ClientStore, 24 cloudAPI func() (AddCloudAPI, error), 25 ) *AddCloudCommand { 26 cloudCallCtx := context.NewCloudCallContext() 27 return &AddCloudCommand{ 28 cloudMetadataStore: cloudMetadataStore, 29 CloudCallCtx: cloudCallCtx, 30 Ping: func(p environs.EnvironProvider, endpoint string) error { 31 return nil 32 }, 33 store: store, 34 addCloudAPIFunc: cloudAPI, 35 } 36 } 37 38 func NewUpdateCloudsCommandForTest(publicCloudURL string) *updateCloudsCommand { 39 return &updateCloudsCommand{ 40 // TODO(wallyworld) - move testing key elsewhere 41 publicSigningKey: sstesting.SignedMetadataPublicKey, 42 publicCloudURL: publicCloudURL, 43 } 44 } 45 46 func NewListCredentialsCommandForTest( 47 testStore jujuclient.CredentialGetter, 48 personalCloudsFunc func() (map[string]jujucloud.Cloud, error), 49 cloudByNameFunc func(string) (*jujucloud.Cloud, error), 50 ) *listCredentialsCommand { 51 return &listCredentialsCommand{ 52 store: testStore, 53 personalCloudsFunc: personalCloudsFunc, 54 cloudByNameFunc: cloudByNameFunc, 55 } 56 } 57 58 func NewDetectCredentialsCommandForTest( 59 testStore jujuclient.CredentialStore, 60 registeredProvidersFunc func() []string, 61 allCloudsFunc func() (map[string]jujucloud.Cloud, error), 62 cloudsByNameFunc func(string) (*jujucloud.Cloud, error), 63 ) *detectCredentialsCommand { 64 return &detectCredentialsCommand{ 65 store: testStore, 66 registeredProvidersFunc: registeredProvidersFunc, 67 allCloudsFunc: allCloudsFunc, 68 cloudByNameFunc: cloudsByNameFunc, 69 } 70 } 71 72 func NewAddCredentialCommandForTest( 73 testStore jujuclient.CredentialStore, 74 cloudByNameFunc func(string) (*jujucloud.Cloud, error), 75 ) *addCredentialCommand { 76 return &addCredentialCommand{ 77 store: testStore, 78 cloudByNameFunc: cloudByNameFunc, 79 } 80 } 81 82 func NewRemoveCredentialCommandForTest(testStore jujuclient.CredentialStore) *removeCredentialCommand { 83 return &removeCredentialCommand{ 84 store: testStore, 85 } 86 } 87 88 func NewSetDefaultCredentialCommandForTest(testStore jujuclient.CredentialStore) *setDefaultCredentialCommand { 89 return &setDefaultCredentialCommand{ 90 store: testStore, 91 } 92 } 93 94 func NewSetDefaultRegionCommandForTest(testStore jujuclient.CredentialStore) *setDefaultRegionCommand { 95 return &setDefaultRegionCommand{ 96 store: testStore, 97 } 98 } 99 100 func NewUpdateCredentialCommandForTest(testStore jujuclient.ClientStore, api credentialAPI) cmd.Command { 101 c := &updateCredentialCommand{ 102 api: api, 103 } 104 c.SetClientStore(testStore) 105 return modelcmd.WrapController(c) 106 } 107 108 func NewShowCredentialCommandForTest(api CredentialContentAPI) cmd.Command { 109 cmd := &showCredentialCommand{newAPIFunc: func() (CredentialContentAPI, error) { 110 return api, nil 111 }} 112 return modelcmd.WrapBase(cmd) 113 }