github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/space/create_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package space_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/cmd/juju/space"
    11  )
    12  
    13  type CreateSuite struct {
    14  	BaseSpaceSuite
    15  }
    16  
    17  var _ = gc.Suite(&CreateSuite{})
    18  
    19  func (s *CreateSuite) SetUpTest(c *gc.C) {
    20  	s.BaseSpaceSuite.SetUpTest(c)
    21  	s.command = space.NewCreateCommand(s.api)
    22  	c.Assert(s.command, gc.NotNil)
    23  }
    24  
    25  func (s *CreateSuite) TestRunWithoutSubnetsSucceeds(c *gc.C) {
    26  	s.AssertRunSucceeds(c,
    27  		`created space "myspace" with no subnets\n`,
    28  		"", // no stdout, just stderr
    29  		"myspace",
    30  	)
    31  
    32  	s.api.CheckCallNames(c, "CreateSpace", "Close")
    33  	s.api.CheckCall(c, 0, "CreateSpace", "myspace", []string(nil), true)
    34  }
    35  
    36  func (s *CreateSuite) TestRunWithSubnetsSucceeds(c *gc.C) {
    37  	s.AssertRunSucceeds(c,
    38  		`created space "myspace" with subnets 10.1.2.0/24, 4.3.2.0/28\n`,
    39  		"", // no stdout, just stderr
    40  		"myspace", "10.1.2.0/24", "4.3.2.0/28",
    41  	)
    42  
    43  	s.api.CheckCallNames(c, "CreateSpace", "Close")
    44  	s.api.CheckCall(c,
    45  		0, "CreateSpace",
    46  		"myspace", s.Strings("10.1.2.0/24", "4.3.2.0/28"), true,
    47  	)
    48  }
    49  
    50  func (s *CreateSuite) TestRunWhenSpacesAPIFails(c *gc.C) {
    51  	s.api.SetErrors(errors.New("API error"))
    52  
    53  	s.AssertRunFails(c,
    54  		`cannot create space "foo": API error`,
    55  		"foo", "10.1.2.0/24",
    56  	)
    57  
    58  	s.api.CheckCallNames(c, "CreateSpace", "Close")
    59  	s.api.CheckCall(c, 0, "CreateSpace", "foo", s.Strings("10.1.2.0/24"), true)
    60  }
    61  
    62  func (s *CreateSuite) TestRunAPIConnectFails(c *gc.C) {
    63  	s.command = space.NewCreateCommand(nil)
    64  	s.AssertRunFails(c,
    65  		"cannot connect to the API server: no environment specified",
    66  		"myspace", "10.20.30.0/24",
    67  	)
    68  	// No API calls recoreded.
    69  	s.api.CheckCallNames(c)
    70  }