github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/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 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/cmd/juju/space" 12 ) 13 14 type CreateSuite struct { 15 BaseSpaceSuite 16 } 17 18 var _ = gc.Suite(&CreateSuite{}) 19 20 func (s *CreateSuite) SetUpTest(c *gc.C) { 21 s.BaseSpaceSuite.SetUpTest(c) 22 s.command = space.NewCreateCommand(s.api) 23 c.Assert(s.command, gc.NotNil) 24 } 25 26 func (s *CreateSuite) TestRunWithoutSubnetsSucceeds(c *gc.C) { 27 s.AssertRunSucceeds(c, 28 `created space "myspace" with no subnets\n`, 29 "", // no stdout, just stderr 30 "myspace", 31 ) 32 33 s.api.CheckCallNames(c, "CreateSpace", "Close") 34 s.api.CheckCall(c, 0, "CreateSpace", "myspace", []string(nil), true) 35 } 36 37 func (s *CreateSuite) TestRunWithSubnetsSucceeds(c *gc.C) { 38 s.AssertRunSucceeds(c, 39 `created space "myspace" with subnets 10.1.2.0/24, 4.3.2.0/28\n`, 40 "", // no stdout, just stderr 41 "myspace", "10.1.2.0/24", "4.3.2.0/28", 42 ) 43 44 s.api.CheckCallNames(c, "CreateSpace", "Close") 45 s.api.CheckCall(c, 46 0, "CreateSpace", 47 "myspace", s.Strings("10.1.2.0/24", "4.3.2.0/28"), true, 48 ) 49 } 50 51 func (s *CreateSuite) TestRunWhenSpacesNotSupported(c *gc.C) { 52 s.api.SetErrors(errors.NewNotSupported(nil, "spaces not supported")) 53 54 err := s.AssertRunSpacesNotSupported(c, 55 `cannot create space "foo": spaces not supported`, 56 "foo", "10.1.2.0/24", 57 ) 58 c.Assert(err, jc.Satisfies, errors.IsNotSupported) 59 60 s.api.CheckCallNames(c, "CreateSpace", "Close") 61 s.api.CheckCall(c, 0, "CreateSpace", "foo", s.Strings("10.1.2.0/24"), true) 62 } 63 64 func (s *CreateSuite) TestRunWhenSpacesAPIFails(c *gc.C) { 65 s.api.SetErrors(errors.New("API error")) 66 67 s.AssertRunFails(c, 68 `cannot create space "foo": API error`, 69 "foo", "10.1.2.0/24", 70 ) 71 72 s.api.CheckCallNames(c, "CreateSpace", "Close") 73 s.api.CheckCall(c, 0, "CreateSpace", "foo", s.Strings("10.1.2.0/24"), true) 74 } 75 76 func (s *CreateSuite) TestRunAPIConnectFails(c *gc.C) { 77 s.command = space.NewCreateCommand(nil) 78 s.AssertRunFails(c, 79 "cannot connect to the API server: no environment specified", 80 "myspace", "10.20.30.0/24", 81 ) 82 // No API calls recoreded. 83 s.api.CheckCallNames(c) 84 }