github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/cloud/list_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package cloud_test 5 6 import ( 7 "io/ioutil" 8 "strings" 9 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 13 jujucloud "github.com/juju/juju/cloud" 14 "github.com/juju/juju/cmd/juju/cloud" 15 "github.com/juju/juju/juju/osenv" 16 _ "github.com/juju/juju/provider/all" 17 "github.com/juju/juju/testing" 18 ) 19 20 type listSuite struct { 21 testing.FakeJujuXDGDataHomeSuite 22 } 23 24 var _ = gc.Suite(&listSuite{}) 25 26 func (s *listSuite) TestListPublic(c *gc.C) { 27 ctx, err := testing.RunCommand(c, cloud.NewListCloudsCommand()) 28 c.Assert(err, jc.ErrorIsNil) 29 out := testing.Stdout(ctx) 30 out = strings.Replace(out, "\n", "", -1) 31 // Just check a snippet of the output to make sure it looks ok. 32 c.Assert(out, gc.Matches, `.*aws-china[ ]*ec2[ ]*cn-north-1.*`) 33 // TODO(wallyworld) - uncomment when we build with go 1.3 or greater 34 // LXD should be there too. 35 //c.Assert(out, gc.Matches, `.*lxd[ ]*lxd[ ]*localhost.*`) 36 // And also manual. 37 c.Assert(out, gc.Matches, `.*manual[ ]*manual[ ].*`) 38 } 39 40 func (s *listSuite) TestListPublicAndPersonal(c *gc.C) { 41 data := ` 42 clouds: 43 homestack: 44 type: openstack 45 auth-types: [userpass, access-key] 46 endpoint: http://homestack 47 regions: 48 london: 49 endpoint: http://london/1.0 50 `[1:] 51 err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("clouds.yaml"), []byte(data), 0600) 52 c.Assert(err, jc.ErrorIsNil) 53 54 ctx, err := testing.RunCommand(c, cloud.NewListCloudsCommand()) 55 c.Assert(err, jc.ErrorIsNil) 56 out := testing.Stdout(ctx) 57 out = strings.Replace(out, "\n", "", -1) 58 // Just check a snippet of the output to make sure it looks ok. 59 // local: clouds are last. 60 c.Assert(out, gc.Matches, `.*local\:homestack[ ]*openstack[ ]*london$`) 61 } 62 63 func (s *listSuite) TestListYAML(c *gc.C) { 64 ctx, err := testing.RunCommand(c, cloud.NewListCloudsCommand(), "--format", "yaml") 65 c.Assert(err, jc.ErrorIsNil) 66 out := testing.Stdout(ctx) 67 out = strings.Replace(out, "\n", "", -1) 68 // Just check a snippet of the output to make sure it looks ok. 69 c.Assert(out, gc.Matches, `.*aws:[ ]*defined: public[ ]*type: ec2[ ]*auth-types: \[access-key\].*`) 70 } 71 72 func (s *listSuite) TestListJSON(c *gc.C) { 73 ctx, err := testing.RunCommand(c, cloud.NewListCloudsCommand(), "--format", "json") 74 c.Assert(err, jc.ErrorIsNil) 75 out := testing.Stdout(ctx) 76 out = strings.Replace(out, "\n", "", -1) 77 // Just check a snippet of the output to make sure it looks ok. 78 c.Assert(out, gc.Matches, `.*{"aws":{"defined":"public","type":"ec2","auth-types":\["access-key"\].*`) 79 } 80 81 func (s *showSuite) TestListPreservesRegionOrder(c *gc.C) { 82 ctx, err := testing.RunCommand(c, cloud.NewListCloudsCommand(), "--format", "yaml") 83 c.Assert(err, jc.ErrorIsNil) 84 lines := strings.Split(testing.Stdout(ctx), "\n") 85 withClouds := "clouds:\n " + strings.Join(lines, "\n ") 86 87 parsedClouds, err := jujucloud.ParseCloudMetadata([]byte(withClouds)) 88 c.Assert(err, jc.ErrorIsNil) 89 parsedCloud, ok := parsedClouds["aws"] 90 c.Assert(ok, jc.IsTrue) // aws found in output 91 92 aws, err := jujucloud.CloudByName("aws") 93 c.Assert(err, jc.ErrorIsNil) 94 c.Assert(&parsedCloud, jc.DeepEquals, aws) 95 }