func (s *DestroyRelationSuite) TestAttemptDestroyingNonExistentRelation(c *C) { s.setUpDestroyRelationScenario(c) err := statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"riak", "wordpress"}, }) c.Assert(err, ErrorMatches, "no relations found") }
func (s *DestroyRelationSuite) TestAttemptDestroyingPeerRelation(c *C) { s.setUpDestroyRelationScenario(c) err := statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"riak:ring"}, }) c.Assert(err, ErrorMatches, `cannot destroy relation "riak:ring": is a peer relation`) }
func (c *DestroyRelationCommand) Run(_ *cmd.Context) error { conn, err := juju.NewConnFromName(c.EnvName) if err != nil { return err } defer conn.Close() params := params.DestroyRelation{ Endpoints: c.Endpoints, } return statecmd.DestroyRelation(conn.State, params) }
func (s *DestroyRelationSuite) TestAttemptDestroyingWithOnlyOneEndpoint(c *C) { s.setUpDestroyRelationScenario(c) // Add a relation between wordpress and mysql. eps, err := s.State.InferEndpoints([]string{"wordpress", "mysql"}) c.Assert(err, IsNil) _, err = s.State.AddRelation(eps...) c.Assert(err, IsNil) err = statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"wordpress"}, }) c.Assert(err, ErrorMatches, "no relations found") }
func (s *DestroyRelationSuite) TestAttemptDestroyingAlreadyDestroyedRelation(c *C) { s.setUpDestroyRelationScenario(c) // Add a relation between wordpress and mysql. eps, err := s.State.InferEndpoints([]string{"wordpress", "mysql"}) c.Assert(err, IsNil) rel, err := s.State.AddRelation(eps...) c.Assert(err, IsNil) err = statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"wordpress", "mysql"}, }) c.Assert(err, IsNil) // Show that the relation was removed. c.Assert(rel.Refresh(), checkers.Satisfies, errors.IsNotFoundError) // And try to destroy it again. err = statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"wordpress", "mysql"}, }) c.Assert(err, ErrorMatches, `relation "wordpress:db mysql:server" not found`) }
func (s *DestroyRelationSuite) TestSuccessfullyDestroyRelation(c *C) { s.setUpDestroyRelationScenario(c) // Add a relation between wordpress and mysql. eps, err := s.State.InferEndpoints([]string{"wordpress", "mysql"}) c.Assert(err, IsNil) rel, err := s.State.AddRelation(eps...) c.Assert(err, IsNil) err = statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"wordpress", "mysql"}, }) c.Assert(err, IsNil) // Show that the relation was removed. c.Assert(rel.Refresh(), checkers.Satisfies, errors.IsNotFoundError) }
func (s *DestroyRelationSuite) TestSuccessfullyDestroyRelationSwapped(c *C) { // Show that the order of the services listed in the DestroyRelation call // does not matter. This is a repeat of the previous test with the service // names swapped. s.setUpDestroyRelationScenario(c) // Add a relation between wordpress and mysql. eps, err := s.State.InferEndpoints([]string{"wordpress", "mysql"}) c.Assert(err, IsNil) rel, err := s.State.AddRelation(eps...) c.Assert(err, IsNil) err = statecmd.DestroyRelation(s.State, params.DestroyRelation{ Endpoints: []string{"mysql", "wordpress"}, }) c.Assert(err, IsNil) // Show that the relation was removed. c.Assert(rel.Refresh(), checkers.Satisfies, errors.IsNotFoundError) }
// DestroyRelation removes the relation between the specified endpoints. func (c *Client) DestroyRelation(args params.DestroyRelation) error { return statecmd.DestroyRelation(c.api.state, args) }