github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/cloud/show_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  
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/cmd/juju/cloud"
    13  	"github.com/juju/juju/juju/osenv"
    14  	_ "github.com/juju/juju/provider/all"
    15  	"github.com/juju/juju/testing"
    16  )
    17  
    18  type showSuite struct {
    19  	testing.FakeJujuXDGDataHomeSuite
    20  }
    21  
    22  var _ = gc.Suite(&showSuite{})
    23  
    24  func (s *showSuite) TestShowBadArgs(c *gc.C) {
    25  	_, err := testing.RunCommand(c, cloud.NewShowCloudCommand())
    26  	c.Assert(err, gc.ErrorMatches, "no cloud specified")
    27  }
    28  
    29  func (s *showSuite) TestShow(c *gc.C) {
    30  	ctx, err := testing.RunCommand(c, cloud.NewShowCloudCommand(), "aws-china")
    31  	c.Assert(err, jc.ErrorIsNil)
    32  	out := testing.Stdout(ctx)
    33  	c.Assert(out, gc.Equals, `
    34  defined: public
    35  type: ec2
    36  auth-types: [access-key]
    37  regions:
    38    cn-north-1:
    39      endpoint: https://ec2.cn-north-1.amazonaws.com.cn/
    40  `[1:])
    41  }
    42  
    43  func (s *showSuite) TestShowWithConfig(c *gc.C) {
    44  	data := `
    45  clouds:
    46    homestack:
    47      type: openstack
    48      auth-types: [userpass, access-key]
    49      endpoint: http://homestack
    50      regions:
    51        london:
    52          endpoint: http://london/1.0
    53      config:
    54        bootstrap-timeout: 1800
    55  `[1:]
    56  	err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("clouds.yaml"), []byte(data), 0600)
    57  
    58  	ctx, err := testing.RunCommand(c, cloud.NewShowCloudCommand(), "homestack")
    59  	c.Assert(err, jc.ErrorIsNil)
    60  	out := testing.Stdout(ctx)
    61  	c.Assert(out, gc.Equals, `
    62  defined: local
    63  type: openstack
    64  auth-types: [userpass, access-key]
    65  endpoint: http://homestack
    66  regions:
    67    london:
    68      endpoint: http://london/1.0
    69  config:
    70    bootstrap-timeout: 1800
    71  `[1:])
    72  }
    73  
    74  func (s *showSuite) TestShowWithRegionConfig(c *gc.C) {
    75  	data := `
    76  clouds:
    77    homestack:
    78      type: openstack
    79      auth-types: [userpass, access-key]
    80      endpoint: http://homestack
    81      regions:
    82        london:
    83          endpoint: http://london/1.0
    84      region-config:
    85        london:
    86          bootstrap-timeout: 1800
    87  `[1:]
    88  	err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("clouds.yaml"), []byte(data), 0600)
    89  
    90  	ctx, err := testing.RunCommand(c, cloud.NewShowCloudCommand(), "homestack")
    91  	c.Assert(err, jc.ErrorIsNil)
    92  	out := testing.Stdout(ctx)
    93  	c.Assert(out, gc.Equals, `
    94  defined: local
    95  type: openstack
    96  auth-types: [userpass, access-key]
    97  endpoint: http://homestack
    98  regions:
    99    london:
   100      endpoint: http://london/1.0
   101  region-config:
   102    london:
   103      bootstrap-timeout: 1800
   104  `[1:])
   105  }