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