4
. "launchpad.net/gocheck"
5
"launchpad.net/juju-core/testing"
8
type AddRelationSuite struct {
12
var _ = Suite(&AddRelationSuite{})
14
func runAddRelation(c *C, args ...string) error {
15
_, err := testing.RunCommand(c, &AddRelationCommand{}, args)
19
var msWpAlreadyExists = `cannot add relation "wp:db ms:server": relation already exists`
20
var msLgAlreadyExists = `cannot add relation "lg:info ms:juju-info": relation already exists`
21
var wpLgAlreadyExists = `cannot add relation "lg:logging-directory wp:logging-dir": relation already exists`
22
var wpLgAlreadyExistsJuju = `cannot add relation "lg:info wp:juju-info": relation already exists`
24
var addRelationTests = []struct {
29
args: []string{"rk", "ms"},
30
err: "no relations found",
32
err: "a relation must involve two services",
35
err: "a relation must involve two services",
37
args: []string{"rk:ring"},
38
err: "a relation must involve two services",
40
args: []string{"ping:pong", "tic:tac", "icki:wacki"},
41
err: "a relation must involve two services",
44
// Add a real relation, and check various ways of failing to re-add it.
46
args: []string{"ms", "wp"},
48
args: []string{"ms", "wp"},
49
err: msWpAlreadyExists,
51
args: []string{"wp", "ms"},
52
err: msWpAlreadyExists,
54
args: []string{"ms", "wp:db"},
55
err: msWpAlreadyExists,
57
args: []string{"ms:server", "wp"},
58
err: msWpAlreadyExists,
60
args: []string{"ms:server", "wp:db"},
61
err: msWpAlreadyExists,
64
// Add a real relation using an implicit endpoint.
66
args: []string{"ms", "lg"},
68
args: []string{"ms", "lg"},
69
err: msLgAlreadyExists,
71
args: []string{"lg", "ms"},
72
err: msLgAlreadyExists,
74
args: []string{"ms:juju-info", "lg"},
75
err: msLgAlreadyExists,
77
args: []string{"ms", "lg:info"},
78
err: msLgAlreadyExists,
80
args: []string{"ms:juju-info", "lg:info"},
81
err: msLgAlreadyExists,
84
// Add a real relation using an explicit endpoint, avoiding the potential implicit one.
86
args: []string{"wp", "lg"},
88
args: []string{"wp", "lg"},
89
err: wpLgAlreadyExists,
91
args: []string{"lg", "wp"},
92
err: wpLgAlreadyExists,
94
args: []string{"wp:logging-dir", "lg"},
95
err: wpLgAlreadyExists,
97
args: []string{"wp", "lg:logging-directory"},
98
err: wpLgAlreadyExists,
100
args: []string{"wp:logging-dir", "lg:logging-directory"},
101
err: wpLgAlreadyExists,
104
// Check we can still use the implicit endpoint if specified explicitly.
106
args: []string{"wp:juju-info", "lg"},
108
args: []string{"wp:juju-info", "lg"},
109
err: wpLgAlreadyExistsJuju,
111
args: []string{"lg", "wp:juju-info"},
112
err: wpLgAlreadyExistsJuju,
114
args: []string{"wp:juju-info", "lg"},
115
err: wpLgAlreadyExistsJuju,
117
args: []string{"wp", "lg:info"},
118
err: wpLgAlreadyExistsJuju,
120
args: []string{"wp:juju-info", "lg:info"},
121
err: wpLgAlreadyExistsJuju,
125
func (s *AddRelationSuite) TestAddRelation(c *C) {
126
testing.Charms.BundlePath(s.seriesPath, "wordpress")
127
err := runDeploy(c, "local:wordpress", "wp")
129
testing.Charms.BundlePath(s.seriesPath, "mysql")
130
err = runDeploy(c, "local:mysql", "ms")
132
testing.Charms.BundlePath(s.seriesPath, "riak")
133
err = runDeploy(c, "local:riak", "rk")
135
testing.Charms.BundlePath(s.seriesPath, "logging")
136
err = runDeploy(c, "local:logging", "lg")
139
for i, t := range addRelationTests {
140
c.Logf("test %d: %v", i, t.args)
141
err := runAddRelation(c, t.args...)
143
c.Assert(err, ErrorMatches, t.err)