github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/cloud/removecredential_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package cloud_test 5 6 import ( 7 "strings" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 jujucloud "github.com/juju/juju/cloud" 13 "github.com/juju/juju/cmd/juju/cloud" 14 "github.com/juju/juju/jujuclient/jujuclienttesting" 15 "github.com/juju/juju/testing" 16 ) 17 18 type removeCredentialSuite struct { 19 testing.BaseSuite 20 } 21 22 var _ = gc.Suite(&removeCredentialSuite{}) 23 24 func (s *removeCredentialSuite) TestBadArgs(c *gc.C) { 25 cmd := cloud.NewRemoveCredentialCommand() 26 _, err := testing.RunCommand(c, cmd) 27 c.Assert(err, gc.ErrorMatches, "Usage: juju remove-credential <cloud-name> <credential-name>") 28 _, err = testing.RunCommand(c, cmd, "cloud", "credential", "extra") 29 c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`) 30 } 31 32 func (s *removeCredentialSuite) TestMissingCredential(c *gc.C) { 33 store := &jujuclienttesting.MemStore{ 34 Credentials: map[string]jujucloud.CloudCredential{ 35 "aws": { 36 AuthCredentials: map[string]jujucloud.Credential{ 37 "my-credential": jujucloud.NewCredential(jujucloud.AccessKeyAuthType, nil), 38 }, 39 }, 40 }, 41 } 42 cmd := cloud.NewRemoveCredentialCommandForTest(store) 43 ctx, err := testing.RunCommand(c, cmd, "aws", "foo") 44 c.Assert(err, jc.ErrorIsNil) 45 output := testing.Stderr(ctx) 46 output = strings.Replace(output, "\n", "", -1) 47 c.Assert(output, gc.Equals, `No credential called "foo" exists for cloud "aws"`) 48 } 49 50 func (s *removeCredentialSuite) TestBadCloudName(c *gc.C) { 51 cmd := cloud.NewRemoveCredentialCommandForTest(jujuclienttesting.NewMemStore()) 52 ctx, err := testing.RunCommand(c, cmd, "somecloud", "foo") 53 c.Assert(err, jc.ErrorIsNil) 54 output := testing.Stderr(ctx) 55 output = strings.Replace(output, "\n", "", -1) 56 c.Assert(output, gc.Equals, `No credentials exist for cloud "somecloud"`) 57 } 58 59 func (s *removeCredentialSuite) TestRemove(c *gc.C) { 60 store := &jujuclienttesting.MemStore{ 61 Credentials: map[string]jujucloud.CloudCredential{ 62 "aws": { 63 AuthCredentials: map[string]jujucloud.Credential{ 64 "my-credential": jujucloud.NewCredential(jujucloud.AccessKeyAuthType, nil), 65 "another-credential": jujucloud.NewCredential(jujucloud.AccessKeyAuthType, nil), 66 }, 67 }, 68 }, 69 } 70 cmd := cloud.NewRemoveCredentialCommandForTest(store) 71 ctx, err := testing.RunCommand(c, cmd, "aws", "my-credential") 72 c.Assert(err, jc.ErrorIsNil) 73 output := testing.Stderr(ctx) 74 output = strings.Replace(output, "\n", "", -1) 75 c.Assert(output, gc.Equals, `Credential "my-credential" for cloud "aws" has been deleted.`) 76 _, stillThere := store.Credentials["aws"].AuthCredentials["my-credential"] 77 c.Assert(stillThere, jc.IsFalse) 78 c.Assert(store.Credentials["aws"].AuthCredentials, gc.HasLen, 1) 79 }