Ejemplo n.º 1
0
func (s *AddRelationSuite) TestCallWithOneEndpointTooMany(c *C) {
	s.setUpAddRelationScenario(c)
	_, err := statecmd.AddRelation(s.State, params.AddRelation{
		Endpoints: []string{"wordpress", "mysql", "logging"},
	})
	c.Assert(err, ErrorMatches, "cannot relate 3 endpoints")
}
Ejemplo n.º 2
0
func (s *AddRelationSuite) TestCallWithOnlyOneEndpoint(c *C) {
	s.setUpAddRelationScenario(c)
	_, err := statecmd.AddRelation(s.State, params.AddRelation{
		Endpoints: []string{"wordpress"},
	})
	c.Assert(err, ErrorMatches, "no relations found")
}
Ejemplo n.º 3
0
func (c *AddRelationCommand) Run(_ *cmd.Context) error {
	conn, err := juju.NewConnFromName(c.EnvName)
	if err != nil {
		return err
	}
	defer conn.Close()
	params := params.AddRelation{
		Endpoints: c.Endpoints,
	}
	_, err = statecmd.AddRelation(conn.State, params)
	return err
}
Ejemplo n.º 4
0
func (s *AddRelationSuite) TestAddAlreadyAddedRelation(c *C) {
	s.setUpAddRelationScenario(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)
	// And try to add it again.
	_, err = statecmd.AddRelation(s.State, params.AddRelation{
		Endpoints: []string{"wordpress", "mysql"},
	})
	c.Assert(err, ErrorMatches, `cannot add relation "wordpress:db mysql:server": relation already exists`)
}
Ejemplo n.º 5
0
func (s *AddRelationSuite) TestSuccessfullyAddRelationSwapped(c *C) {
	s.setUpAddRelationScenario(c)
	res, err := statecmd.AddRelation(s.State, params.AddRelation{
		Endpoints: []string{"mysql", "wordpress"},
	})
	c.Assert(err, IsNil)
	s.checkEndpoints(c, res)
	// Show that the relation was added.
	wpSvc, err := s.State.Service("wordpress")
	c.Assert(err, IsNil)
	rels, err := wpSvc.Relations()
	c.Assert(len(rels), Equals, 1)
	mySvc, err := s.State.Service("mysql")
	c.Assert(err, IsNil)
	rels, err = mySvc.Relations()
	c.Assert(len(rels), Equals, 1)
}
Ejemplo n.º 6
0
// AddRelation adds a relation between the specified endpoints and returns the relation info.
func (c *Client) AddRelation(args params.AddRelation) (params.AddRelationResults, error) {
	return statecmd.AddRelation(c.api.state, args)
}