github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/space/add_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 AddSuite struct { 15 BaseSpaceSuite 16 } 17 18 var _ = gc.Suite(&AddSuite{}) 19 20 func (s *AddSuite) SetUpTest(c *gc.C) { 21 s.BaseSpaceSuite.SetUpTest(c) 22 s.command = space.NewAddCommandForTest(s.api) 23 c.Assert(s.command, gc.NotNil) 24 } 25 26 func (s *AddSuite) TestRunWithoutSubnetsSucceeds(c *gc.C) { 27 s.AssertRunSucceeds(c, 28 `added space "myspace" with no subnets\n`, 29 "", // no stdout, just stderr 30 "myspace", 31 ) 32 33 s.api.CheckCallNames(c, "AddSpace", "Close") 34 s.api.CheckCall(c, 0, "AddSpace", "myspace", []string(nil), true) 35 } 36 37 func (s *AddSuite) TestRunWithSubnetsSucceeds(c *gc.C) { 38 s.AssertRunSucceeds(c, 39 `added 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, "AddSpace", "Close") 45 s.api.CheckCall(c, 46 0, "AddSpace", 47 "myspace", s.Strings("10.1.2.0/24", "4.3.2.0/28"), true, 48 ) 49 } 50 51 func (s *AddSuite) TestRunWhenSpacesNotSupported(c *gc.C) { 52 s.api.SetErrors(errors.NewNotSupported(nil, "spaces not supported")) 53 54 err := s.AssertRunSpacesNotSupported(c, 55 `cannot add 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, "AddSpace", "Close") 61 s.api.CheckCall(c, 0, "AddSpace", "foo", s.Strings("10.1.2.0/24"), true) 62 } 63 64 func (s *AddSuite) TestRunWhenSpacesAPIFails(c *gc.C) { 65 s.api.SetErrors(errors.New("API error")) 66 67 s.AssertRunFails(c, 68 `cannot add space "foo": API error`, 69 "foo", "10.1.2.0/24", 70 ) 71 72 s.api.CheckCallNames(c, "AddSpace", "Close") 73 s.api.CheckCall(c, 0, "AddSpace", "foo", s.Strings("10.1.2.0/24"), true) 74 }