github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/cmd/juju/destroyrelation_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  	gc "launchpad.net/gocheck"
     8  
     9  	jujutesting "launchpad.net/juju-core/juju/testing"
    10  	"launchpad.net/juju-core/testing"
    11  )
    12  
    13  type DestroyRelationSuite struct {
    14  	jujutesting.RepoSuite
    15  }
    16  
    17  var _ = gc.Suite(&DestroyRelationSuite{})
    18  
    19  func runDestroyRelation(c *gc.C, args ...string) error {
    20  	_, err := testing.RunCommand(c, &DestroyRelationCommand{}, args)
    21  	return err
    22  }
    23  
    24  func (s *DestroyRelationSuite) TestDestroyRelation(c *gc.C) {
    25  	testing.Charms.BundlePath(s.SeriesPath, "riak")
    26  	err := runDeploy(c, "local:riak", "riak")
    27  	c.Assert(err, gc.IsNil)
    28  	testing.Charms.BundlePath(s.SeriesPath, "logging")
    29  	err = runDeploy(c, "local:logging", "logging")
    30  	c.Assert(err, gc.IsNil)
    31  	runAddRelation(c, "riak", "logging")
    32  
    33  	// Destroy a relation that exists.
    34  	err = runDestroyRelation(c, "logging", "riak")
    35  	c.Assert(err, gc.IsNil)
    36  
    37  	// Destroy a relation that used to exist.
    38  	err = runDestroyRelation(c, "riak", "logging")
    39  	c.Assert(err, gc.ErrorMatches, `relation "logging:info riak:juju-info" not found`)
    40  
    41  	// Invalid removes.
    42  	err = runDestroyRelation(c, "ping", "pong")
    43  	c.Assert(err, gc.ErrorMatches, `service "ping" not found`)
    44  	err = runDestroyRelation(c, "riak")
    45  	c.Assert(err, gc.ErrorMatches, `a relation must involve two services`)
    46  }