Ejemplo n.º 1
0
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")
}
Ejemplo n.º 2
0
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`)
}
Ejemplo n.º 3
0
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)
}
Ejemplo n.º 4
0
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")
}
Ejemplo n.º 5
0
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`)
}
Ejemplo n.º 6
0
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)
}
Ejemplo n.º 7
0
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)
}
Ejemplo n.º 8
0
// DestroyRelation removes the relation between the specified endpoints.
func (c *Client) DestroyRelation(args params.DestroyRelation) error {
	return statecmd.DestroyRelation(c.api.state, args)
}