github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/space/remove_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 "github.com/juju/juju/feature" 13 ) 14 15 type RemoveSuite struct { 16 BaseSpaceSuite 17 } 18 19 var _ = gc.Suite(&RemoveSuite{}) 20 21 func (s *RemoveSuite) SetUpTest(c *gc.C) { 22 s.BaseSuite.SetFeatureFlags(feature.PostNetCLIMVP) 23 s.BaseSpaceSuite.SetUpTest(c) 24 s.newCommand = space.NewRemoveCommand 25 } 26 27 func (s *RemoveSuite) TestInit(c *gc.C) { 28 for i, test := range []struct { 29 about string 30 args []string 31 expectName string 32 expectErr string 33 }{{ 34 about: "no arguments", 35 expectErr: "space name is required", 36 }, { 37 about: "invalid space name", 38 args: s.Strings("%inv$alid", "new-name"), 39 expectErr: `"%inv\$alid" is not a valid space name`, 40 }, { 41 about: "multiple space names aren't allowed", 42 args: s.Strings("a-space", "another-space"), 43 expectErr: `unrecognized args: \["another-space"\]`, 44 expectName: "a-space", 45 }, { 46 about: "delete a valid space name", 47 args: s.Strings("myspace"), 48 expectName: "myspace", 49 }} { 50 c.Logf("test #%d: %s", i, test.about) 51 command, err := s.InitCommand(c, test.args...) 52 if test.expectErr != "" { 53 prefixedErr := "invalid arguments specified: " + test.expectErr 54 c.Check(err, gc.ErrorMatches, prefixedErr) 55 } else { 56 c.Check(err, jc.ErrorIsNil) 57 command := command.(*space.RemoveCommand) 58 c.Check(command.Name(), gc.Equals, test.expectName) 59 } 60 // No API calls should be recorded at this stage. 61 s.api.CheckCallNames(c) 62 } 63 } 64 65 func (s *RemoveSuite) TestRunWithValidSpaceSucceeds(c *gc.C) { 66 s.AssertRunSucceeds(c, 67 `removed space "myspace"\n`, 68 "", // no stdout, just stderr 69 "myspace", 70 ) 71 72 s.api.CheckCallNames(c, "RemoveSpace", "Close") 73 s.api.CheckCall(c, 0, "RemoveSpace", "myspace") 74 } 75 76 func (s *RemoveSuite) TestRunWhenSpacesAPIFails(c *gc.C) { 77 s.api.SetErrors(errors.New("boom")) 78 79 s.AssertRunFails(c, 80 `cannot remove space "myspace": boom`, 81 "myspace", 82 ) 83 84 s.api.CheckCallNames(c, "RemoveSpace", "Close") 85 s.api.CheckCall(c, 0, "RemoveSpace", "myspace") 86 }