~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cmd/juju/addrelation_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package main
 
2
 
 
3
import (
 
4
        . "launchpad.net/gocheck"
 
5
        "launchpad.net/juju-core/testing"
 
6
)
 
7
 
 
8
type AddRelationSuite struct {
 
9
        repoSuite
 
10
}
 
11
 
 
12
var _ = Suite(&AddRelationSuite{})
 
13
 
 
14
func runAddRelation(c *C, args ...string) error {
 
15
        _, err := testing.RunCommand(c, &AddRelationCommand{}, args)
 
16
        return err
 
17
}
 
18
 
 
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`
 
23
 
 
24
var addRelationTests = []struct {
 
25
        args []string
 
26
        err  string
 
27
}{
 
28
        {
 
29
                args: []string{"rk", "ms"},
 
30
                err:  "no relations found",
 
31
        }, {
 
32
                err: "a relation must involve two services",
 
33
        }, {
 
34
                args: []string{"rk"},
 
35
                err:  "a relation must involve two services",
 
36
        }, {
 
37
                args: []string{"rk:ring"},
 
38
                err:  "a relation must involve two services",
 
39
        }, {
 
40
                args: []string{"ping:pong", "tic:tac", "icki:wacki"},
 
41
                err:  "a relation must involve two services",
 
42
        },
 
43
 
 
44
        // Add a real relation, and check various ways of failing to re-add it.
 
45
        {
 
46
                args: []string{"ms", "wp"},
 
47
        }, {
 
48
                args: []string{"ms", "wp"},
 
49
                err:  msWpAlreadyExists,
 
50
        }, {
 
51
                args: []string{"wp", "ms"},
 
52
                err:  msWpAlreadyExists,
 
53
        }, {
 
54
                args: []string{"ms", "wp:db"},
 
55
                err:  msWpAlreadyExists,
 
56
        }, {
 
57
                args: []string{"ms:server", "wp"},
 
58
                err:  msWpAlreadyExists,
 
59
        }, {
 
60
                args: []string{"ms:server", "wp:db"},
 
61
                err:  msWpAlreadyExists,
 
62
        },
 
63
 
 
64
        // Add a real relation using an implicit endpoint.
 
65
        {
 
66
                args: []string{"ms", "lg"},
 
67
        }, {
 
68
                args: []string{"ms", "lg"},
 
69
                err:  msLgAlreadyExists,
 
70
        }, {
 
71
                args: []string{"lg", "ms"},
 
72
                err:  msLgAlreadyExists,
 
73
        }, {
 
74
                args: []string{"ms:juju-info", "lg"},
 
75
                err:  msLgAlreadyExists,
 
76
        }, {
 
77
                args: []string{"ms", "lg:info"},
 
78
                err:  msLgAlreadyExists,
 
79
        }, {
 
80
                args: []string{"ms:juju-info", "lg:info"},
 
81
                err:  msLgAlreadyExists,
 
82
        },
 
83
 
 
84
        // Add a real relation using an explicit endpoint, avoiding the potential implicit one.
 
85
        {
 
86
                args: []string{"wp", "lg"},
 
87
        }, {
 
88
                args: []string{"wp", "lg"},
 
89
                err:  wpLgAlreadyExists,
 
90
        }, {
 
91
                args: []string{"lg", "wp"},
 
92
                err:  wpLgAlreadyExists,
 
93
        }, {
 
94
                args: []string{"wp:logging-dir", "lg"},
 
95
                err:  wpLgAlreadyExists,
 
96
        }, {
 
97
                args: []string{"wp", "lg:logging-directory"},
 
98
                err:  wpLgAlreadyExists,
 
99
        }, {
 
100
                args: []string{"wp:logging-dir", "lg:logging-directory"},
 
101
                err:  wpLgAlreadyExists,
 
102
        },
 
103
 
 
104
        // Check we can still use the implicit endpoint if specified explicitly.
 
105
        {
 
106
                args: []string{"wp:juju-info", "lg"},
 
107
        }, {
 
108
                args: []string{"wp:juju-info", "lg"},
 
109
                err:  wpLgAlreadyExistsJuju,
 
110
        }, {
 
111
                args: []string{"lg", "wp:juju-info"},
 
112
                err:  wpLgAlreadyExistsJuju,
 
113
        }, {
 
114
                args: []string{"wp:juju-info", "lg"},
 
115
                err:  wpLgAlreadyExistsJuju,
 
116
        }, {
 
117
                args: []string{"wp", "lg:info"},
 
118
                err:  wpLgAlreadyExistsJuju,
 
119
        }, {
 
120
                args: []string{"wp:juju-info", "lg:info"},
 
121
                err:  wpLgAlreadyExistsJuju,
 
122
        },
 
123
}
 
124
 
 
125
func (s *AddRelationSuite) TestAddRelation(c *C) {
 
126
        testing.Charms.BundlePath(s.seriesPath, "wordpress")
 
127
        err := runDeploy(c, "local:wordpress", "wp")
 
128
        c.Assert(err, IsNil)
 
129
        testing.Charms.BundlePath(s.seriesPath, "mysql")
 
130
        err = runDeploy(c, "local:mysql", "ms")
 
131
        c.Assert(err, IsNil)
 
132
        testing.Charms.BundlePath(s.seriesPath, "riak")
 
133
        err = runDeploy(c, "local:riak", "rk")
 
134
        c.Assert(err, IsNil)
 
135
        testing.Charms.BundlePath(s.seriesPath, "logging")
 
136
        err = runDeploy(c, "local:logging", "lg")
 
137
        c.Assert(err, IsNil)
 
138
 
 
139
        for i, t := range addRelationTests {
 
140
                c.Logf("test %d: %v", i, t.args)
 
141
                err := runAddRelation(c, t.args...)
 
142
                if t.err != "" {
 
143
                        c.Assert(err, ErrorMatches, t.err)
 
144
                }
 
145
        }
 
146
}