Пример #1
0
func (s *EndpointSuite) TestCanRelate(c *C) {
	for i, t := range canRelateTests {
		c.Logf("test %d", i)
		ep1 := state.Endpoint{
			ServiceName: "one-service",
			Relation: charm.Relation{
				Interface: "ifce",
				Name:      "foo",
				Role:      t.role1,
				Scope:     charm.ScopeGlobal,
			},
		}
		ep2 := state.Endpoint{
			ServiceName: "another-service",
			Relation: charm.Relation{
				Interface: "ifce",
				Name:      "bar",
				Role:      t.role2,
				Scope:     charm.ScopeGlobal,
			},
		}
		if t.success {
			c.Assert(ep1.CanRelateTo(ep2), Equals, true)
			c.Assert(ep2.CanRelateTo(ep1), Equals, true)
			ep1.Interface = "different"
		}
		c.Assert(ep1.CanRelateTo(ep2), Equals, false)
		c.Assert(ep2.CanRelateTo(ep1), Equals, false)
	}
	ep1 := state.Endpoint{
		ServiceName: "same-service",
		Relation: charm.Relation{
			Interface: "ifce",
			Name:      "foo",
			Role:      charm.RoleProvider,
			Scope:     charm.ScopeGlobal,
		},
	}
	ep2 := state.Endpoint{
		ServiceName: "same-service",
		Relation: charm.Relation{
			Interface: "ifce",
			Name:      "bar",
			Role:      charm.RoleRequirer,
			Scope:     charm.ScopeGlobal,
		},
	}
	c.Assert(ep1.CanRelateTo(ep2), Equals, false)
	c.Assert(ep2.CanRelateTo(ep1), Equals, false)
}
Пример #2
0
func (s *EndpointSuite) TestCanRelate(c *C) {
	for i, t := range canRelateTests {
		c.Logf("test %d", i)
		ep1 := state.Endpoint{"one-service", "ifce", "foo", t.role1, charm.ScopeGlobal}
		ep2 := state.Endpoint{"another-service", "ifce", "bar", t.role2, charm.ScopeGlobal}
		if t.success {
			c.Assert(ep1.CanRelateTo(ep2), Equals, true)
			c.Assert(ep2.CanRelateTo(ep1), Equals, true)
			ep1.Interface = "different"
		}
		c.Assert(ep1.CanRelateTo(ep2), Equals, false)
		c.Assert(ep2.CanRelateTo(ep1), Equals, false)
	}
	ep1 := state.Endpoint{"same-service", "ifce", "foo", state.RoleProvider, charm.ScopeGlobal}
	ep2 := state.Endpoint{"same-service", "ifce", "bar", state.RoleRequirer, charm.ScopeGlobal}
	c.Assert(ep1.CanRelateTo(ep2), Equals, false)
	c.Assert(ep2.CanRelateTo(ep1), Equals, false)
}