github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/service/removerelation_test.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package service
     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/common"
    12  	jujutesting "github.com/juju/juju/juju/testing"
    13  	"github.com/juju/juju/rpc"
    14  	"github.com/juju/juju/testcharms"
    15  	"github.com/juju/juju/testing"
    16  )
    17  
    18  type RemoveRelationSuite struct {
    19  	jujutesting.RepoSuite
    20  	common.CmdBlockHelper
    21  }
    22  
    23  func (s *RemoveRelationSuite) SetUpTest(c *gc.C) {
    24  	s.RepoSuite.SetUpTest(c)
    25  	s.CmdBlockHelper = common.NewCmdBlockHelper(s.APIState)
    26  	c.Assert(s.CmdBlockHelper, gc.NotNil)
    27  	s.AddCleanup(func(*gc.C) { s.CmdBlockHelper.Close() })
    28  }
    29  
    30  var _ = gc.Suite(&RemoveRelationSuite{})
    31  
    32  func runRemoveRelation(c *gc.C, args ...string) error {
    33  	_, err := testing.RunCommand(c, NewRemoveRelationCommand(), args...)
    34  	return err
    35  }
    36  
    37  func (s *RemoveRelationSuite) setupRelationForRemove(c *gc.C) {
    38  	ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "riak")
    39  	err := runDeploy(c, ch, "riak", "--series", "quantal")
    40  	c.Assert(err, jc.ErrorIsNil)
    41  	ch = testcharms.Repo.CharmArchivePath(s.CharmsPath, "logging")
    42  	err = runDeploy(c, ch, "logging", "--series", "quantal")
    43  	c.Assert(err, jc.ErrorIsNil)
    44  	runAddRelation(c, "riak", "logging")
    45  }
    46  
    47  func (s *RemoveRelationSuite) TestRemoveRelation(c *gc.C) {
    48  	s.setupRelationForRemove(c)
    49  
    50  	// Destroy a relation that exists.
    51  	err := runRemoveRelation(c, "logging", "riak")
    52  	c.Assert(err, jc.ErrorIsNil)
    53  
    54  	// Destroy a relation that used to exist.
    55  	err = runRemoveRelation(c, "riak", "logging")
    56  	c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
    57  		Message: `relation "logging:info riak:juju-info" not found`,
    58  		Code:    "not found",
    59  	})
    60  
    61  	// Invalid removes.
    62  	err = runRemoveRelation(c, "ping", "pong")
    63  	c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
    64  		Message: `service "ping" not found`,
    65  		Code:    "not found",
    66  	})
    67  	err = runRemoveRelation(c, "riak")
    68  	c.Assert(err, gc.ErrorMatches, `a relation must involve two services`)
    69  }
    70  
    71  func (s *RemoveRelationSuite) TestBlockRemoveRelation(c *gc.C) {
    72  	s.setupRelationForRemove(c)
    73  
    74  	// block operation
    75  	s.BlockRemoveObject(c, "TestBlockRemoveRelation")
    76  	// Destroy a relation that exists.
    77  	err := runRemoveRelation(c, "logging", "riak")
    78  	s.AssertBlocked(c, err, ".*TestBlockRemoveRelation.*")
    79  }