github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/removeunit_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package main 5 6 import ( 7 "fmt" 8 "strings" 9 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 "gopkg.in/juju/charm.v4" 13 14 "github.com/juju/cmd" 15 "github.com/juju/juju/cmd/envcmd" 16 jujutesting "github.com/juju/juju/juju/testing" 17 "github.com/juju/juju/state" 18 "github.com/juju/juju/testcharms" 19 "github.com/juju/juju/testing" 20 ) 21 22 type RemoveUnitSuite struct { 23 jujutesting.RepoSuite 24 } 25 26 var _ = gc.Suite(&RemoveUnitSuite{}) 27 28 func runRemoveUnit(c *gc.C, args ...string) error { 29 _, err := testing.RunCommand(c, envcmd.Wrap(&RemoveUnitCommand{}), args...) 30 return err 31 } 32 33 func (s *RemoveUnitSuite) setupUnitForRemove(c *gc.C) *state.Service { 34 testcharms.Repo.CharmArchivePath(s.SeriesPath, "dummy") 35 err := runDeploy(c, "-n", "2", "local:dummy", "dummy") 36 c.Assert(err, jc.ErrorIsNil) 37 curl := charm.MustParseURL(fmt.Sprintf("local:%s/dummy-1", testing.FakeDefaultSeries)) 38 svc, _ := s.AssertService(c, "dummy", curl, 2, 0) 39 return svc 40 } 41 42 func (s *RemoveUnitSuite) TestRemoveUnit(c *gc.C) { 43 svc := s.setupUnitForRemove(c) 44 45 err := runRemoveUnit(c, "dummy/0", "dummy/1", "dummy/2", "sillybilly/17") 46 c.Assert(err, gc.ErrorMatches, `some units were not destroyed: unit "dummy/2" does not exist; unit "sillybilly/17" does not exist`) 47 units, err := svc.AllUnits() 48 c.Assert(err, jc.ErrorIsNil) 49 for _, u := range units { 50 c.Assert(u.Life(), gc.Equals, state.Dying) 51 } 52 } 53 func (s *RemoveUnitSuite) TestBlockRemoveUnit(c *gc.C) { 54 svc := s.setupUnitForRemove(c) 55 56 // block operation 57 s.AssertConfigParameterUpdated(c, "block-remove-object", true) 58 err := runRemoveUnit(c, "dummy/0", "dummy/1") 59 c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) 60 c.Assert(svc.Life(), gc.Equals, state.Alive) 61 62 // msg is logged 63 stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) 64 c.Check(stripped, gc.Matches, ".*To unblock removal.*") 65 }