LEFT | RIGHT |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "io/ioutil" | 5 "io/ioutil" |
6 . "launchpad.net/gocheck" | 6 . "launchpad.net/gocheck" |
7 "launchpad.net/juju-core/charm" | 7 "launchpad.net/juju-core/charm" |
8 "launchpad.net/juju-core/state" | 8 "launchpad.net/juju-core/state" |
9 "launchpad.net/juju-core/testing" | 9 "launchpad.net/juju-core/testing" |
10 "os" | 10 "os" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 err := runUpgradeCharm(c, "phony") | 49 err := runUpgradeCharm(c, "phony") |
50 c.Assert(err, ErrorMatches, `service "phony" not found`) | 50 c.Assert(err, ErrorMatches, `service "phony" not found`) |
51 } | 51 } |
52 | 52 |
53 func (s *UpgradeCharmErrorsSuite) TestCannotBumpRevisionWithBundle(c *C) { | 53 func (s *UpgradeCharmErrorsSuite) TestCannotBumpRevisionWithBundle(c *C) { |
54 testing.Charms.BundlePath(s.seriesPath, "riak") | 54 testing.Charms.BundlePath(s.seriesPath, "riak") |
55 err := runDeploy(c, "local:riak", "riak") | 55 err := runDeploy(c, "local:riak", "riak") |
56 c.Assert(err, IsNil) | 56 c.Assert(err, IsNil) |
57 | 57 |
58 err = runUpgradeCharm(c, "riak") | 58 err = runUpgradeCharm(c, "riak") |
59 » c.Assert(err, ErrorMatches, `already running latest charm "local:precise
/riak-7"`) | 59 » c.Assert(err, ErrorMatches, `cannot increment revision of charm "local:p
recise/riak-7": not a directory`) |
60 } | 60 } |
61 | 61 |
62 func (s *UpgradeCharmErrorsSuite) deployService(c *C) { | 62 func (s *UpgradeCharmErrorsSuite) deployService(c *C) { |
63 testing.Charms.ClonedDirPath(s.seriesPath, "riak") | 63 testing.Charms.ClonedDirPath(s.seriesPath, "riak") |
64 err := runDeploy(c, "local:riak", "riak") | 64 err := runDeploy(c, "local:riak", "riak") |
65 c.Assert(err, IsNil) | 65 c.Assert(err, IsNil) |
66 } | 66 } |
67 | 67 |
68 func (s *UpgradeCharmErrorsSuite) TestInvalidSwitchURL(c *C) { | 68 func (s *UpgradeCharmErrorsSuite) TestInvalidSwitchURL(c *C) { |
69 s.deployService(c) | 69 s.deployService(c) |
70 err := runUpgradeCharm(c, "riak", "--switch=blah") | 70 err := runUpgradeCharm(c, "riak", "--switch=blah") |
71 c.Assert(err, ErrorMatches, "charm not found: cs:precise/blah") | 71 c.Assert(err, ErrorMatches, "charm not found: cs:precise/blah") |
72 » err = runUpgradeCharm(c, "riak", "--switch=local:missing/one") | 72 » err = runUpgradeCharm(c, "riak", "--switch=cs:missing/one") |
73 » c.Assert(err, ErrorMatches, `no charms found matching "local:missing/one
" in .*`) | 73 » c.Assert(err, ErrorMatches, "charm not found: cs:missing/one") |
74 // TODO(dimitern): add tests with incompatible charms | 74 // TODO(dimitern): add tests with incompatible charms |
75 } | 75 } |
76 | 76 |
77 func (s *UpgradeCharmErrorsSuite) TestSwitchAndRevisionFails(c *C) { | 77 func (s *UpgradeCharmErrorsSuite) TestSwitchAndRevisionFails(c *C) { |
78 s.deployService(c) | 78 s.deployService(c) |
79 err := runUpgradeCharm(c, "riak", "--switch=riak", "--revision=2") | 79 err := runUpgradeCharm(c, "riak", "--switch=riak", "--revision=2") |
80 » c.Assert(err, ErrorMatches, "cannot specify --switch and --revision toge
ther") | 80 » c.Assert(err, ErrorMatches, "--switch and --revision are mutually exclus
ive") |
81 } | 81 } |
82 | 82 |
83 func (s *UpgradeCharmErrorsSuite) TestInvalidRevision(c *C) { | 83 func (s *UpgradeCharmErrorsSuite) TestInvalidRevision(c *C) { |
84 s.deployService(c) | 84 s.deployService(c) |
85 err := runUpgradeCharm(c, "riak", "--revision=blah") | 85 err := runUpgradeCharm(c, "riak", "--revision=blah") |
86 c.Assert(err, ErrorMatches, `invalid value "blah" for flag --revision: s
trconv.ParseInt: parsing "blah": invalid syntax`) | 86 c.Assert(err, ErrorMatches, `invalid value "blah" for flag --revision: s
trconv.ParseInt: parsing "blah": invalid syntax`) |
87 } | 87 } |
88 | 88 |
89 type UpgradeCharmSuccessSuite struct { | 89 type UpgradeCharmSuccessSuite struct { |
90 repoSuite | 90 repoSuite |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 peers: | 179 peers: |
180 ring: | 180 ring: |
181 interface: riak | 181 interface: riak |
182 `) | 182 `) |
183 | 183 |
184 func (s *UpgradeCharmSuccessSuite) TestSwitch(c *C) { | 184 func (s *UpgradeCharmSuccessSuite) TestSwitch(c *C) { |
185 myriakPath := testing.Charms.RenamedClonedDirPath(s.seriesPath, "riak",
"myriak") | 185 myriakPath := testing.Charms.RenamedClonedDirPath(s.seriesPath, "riak",
"myriak") |
186 err := ioutil.WriteFile(path.Join(myriakPath, "metadata.yaml"), myriakMe
ta, 0644) | 186 err := ioutil.WriteFile(path.Join(myriakPath, "metadata.yaml"), myriakMe
ta, 0644) |
187 c.Assert(err, IsNil) | 187 c.Assert(err, IsNil) |
188 | 188 |
189 » // Test with local repo. | 189 » // Test with local repo and no explicit revsion. |
190 err = runUpgradeCharm(c, "riak", "--switch=local:myriak") | 190 err = runUpgradeCharm(c, "riak", "--switch=local:myriak") |
191 c.Assert(err, IsNil) | 191 c.Assert(err, IsNil) |
192 curl := s.assertUpgraded(c, 7, false) | 192 curl := s.assertUpgraded(c, 7, false) |
193 c.Assert(curl.String(), Equals, "local:precise/myriak-7") | 193 c.Assert(curl.String(), Equals, "local:precise/myriak-7") |
194 s.assertLocalRevision(c, 7, myriakPath) | 194 s.assertLocalRevision(c, 7, myriakPath) |
195 } | 195 |
| 196 » // Try it again without revision - should be bumped. |
| 197 » err = runUpgradeCharm(c, "riak", "--switch=local:myriak") |
| 198 » c.Assert(err, IsNil) |
| 199 » curl = s.assertUpgraded(c, 8, false) |
| 200 » c.Assert(curl.String(), Equals, "local:precise/myriak-8") |
| 201 » s.assertLocalRevision(c, 8, myriakPath) |
| 202 |
| 203 » // Now try the same with explicit revision - should fail. |
| 204 » err = runUpgradeCharm(c, "riak", "--switch=local:myriak-8") |
| 205 » c.Assert(err, ErrorMatches, `already running specified charm "local:prec
ise/myriak-8"`) |
| 206 |
| 207 » // Change the revision to 42 and upgrade to it with explicit revision. |
| 208 » err = ioutil.WriteFile(path.Join(myriakPath, "revision"), []byte("42"),
0644) |
| 209 » c.Assert(err, IsNil) |
| 210 » err = runUpgradeCharm(c, "riak", "--switch=local:myriak-42") |
| 211 » c.Assert(err, IsNil) |
| 212 » curl = s.assertUpgraded(c, 42, false) |
| 213 » c.Assert(curl.String(), Equals, "local:precise/myriak-42") |
| 214 » s.assertLocalRevision(c, 42, myriakPath) |
| 215 } |
LEFT | RIGHT |