github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/removerelation_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 "strings" 8 9 "github.com/juju/cmd" 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/cmd/envcmd" 14 jujutesting "github.com/juju/juju/juju/testing" 15 "github.com/juju/juju/testcharms" 16 "github.com/juju/juju/testing" 17 ) 18 19 type RemoveRelationSuite struct { 20 jujutesting.RepoSuite 21 } 22 23 var _ = gc.Suite(&RemoveRelationSuite{}) 24 25 func runRemoveRelation(c *gc.C, args ...string) error { 26 _, err := testing.RunCommand(c, envcmd.Wrap(&RemoveRelationCommand{}), args...) 27 return err 28 } 29 30 func (s *RemoveRelationSuite) setupRelationForRemove(c *gc.C) { 31 testcharms.Repo.CharmArchivePath(s.SeriesPath, "riak") 32 err := runDeploy(c, "local:riak", "riak") 33 c.Assert(err, jc.ErrorIsNil) 34 testcharms.Repo.CharmArchivePath(s.SeriesPath, "logging") 35 err = runDeploy(c, "local:logging", "logging") 36 c.Assert(err, jc.ErrorIsNil) 37 runAddRelation(c, "riak", "logging") 38 } 39 40 func (s *RemoveRelationSuite) TestRemoveRelation(c *gc.C) { 41 s.setupRelationForRemove(c) 42 43 // Destroy a relation that exists. 44 err := runRemoveRelation(c, "logging", "riak") 45 c.Assert(err, jc.ErrorIsNil) 46 47 // Destroy a relation that used to exist. 48 err = runRemoveRelation(c, "riak", "logging") 49 c.Assert(err, gc.ErrorMatches, `relation "logging:info riak:juju-info" not found`) 50 51 // Invalid removes. 52 err = runRemoveRelation(c, "ping", "pong") 53 c.Assert(err, gc.ErrorMatches, `service "ping" not found`) 54 err = runRemoveRelation(c, "riak") 55 c.Assert(err, gc.ErrorMatches, `a relation must involve two services`) 56 } 57 58 func (s *RemoveRelationSuite) TestBlockRemoveRelation(c *gc.C) { 59 s.setupRelationForRemove(c) 60 61 // block operation 62 s.AssertConfigParameterUpdated(c, "block-remove-object", true) 63 // Destroy a relation that exists. 64 err := runRemoveRelation(c, "logging", "riak") 65 c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) 66 67 // msg is logged 68 stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) 69 c.Check(stripped, gc.Matches, ".*To unblock removal.*") 70 }