Index: cmd/juju/upgradecharm_test.go |
=== modified file 'cmd/juju/upgradecharm_test.go' |
--- cmd/juju/upgradecharm_test.go 2013-03-27 15:42:27 +0000 |
+++ cmd/juju/upgradecharm_test.go 2013-04-29 16:40:25 +0000 |
@@ -54,8 +54,36 @@ |
testing.Charms.BundlePath(s.seriesPath, "riak") |
err := runDeploy(c, "local:riak", "riak") |
c.Assert(err, IsNil) |
+ |
err = runUpgradeCharm(c, "riak") |
- c.Assert(err, ErrorMatches, `already running latest charm "local:precise/riak-7"`) |
+ c.Assert(err, ErrorMatches, `cannot increment revision of charm "local:precise/riak-7": not a directory`) |
+} |
+ |
+func (s *UpgradeCharmErrorsSuite) deployService(c *C) { |
+ testing.Charms.ClonedDirPath(s.seriesPath, "riak") |
+ err := runDeploy(c, "local:riak", "riak") |
+ c.Assert(err, IsNil) |
+} |
+ |
+func (s *UpgradeCharmErrorsSuite) TestInvalidSwitchURL(c *C) { |
+ s.deployService(c) |
+ err := runUpgradeCharm(c, "riak", "--switch=blah") |
+ c.Assert(err, ErrorMatches, "charm not found: cs:precise/blah") |
+ err = runUpgradeCharm(c, "riak", "--switch=cs:missing/one") |
+ c.Assert(err, ErrorMatches, "charm not found: cs:missing/one") |
+ // TODO(dimitern): add tests with incompatible charms |
+} |
+ |
+func (s *UpgradeCharmErrorsSuite) TestSwitchAndRevisionFails(c *C) { |
+ s.deployService(c) |
+ err := runUpgradeCharm(c, "riak", "--switch=riak", "--revision=2") |
+ c.Assert(err, ErrorMatches, "--switch and --revision are mutually exclusive") |
+} |
+ |
+func (s *UpgradeCharmErrorsSuite) TestInvalidRevision(c *C) { |
+ s.deployService(c) |
+ err := runUpgradeCharm(c, "riak", "--revision=blah") |
+ c.Assert(err, ErrorMatches, `invalid value "blah" for flag --revision: strconv.ParseInt: parsing "blah": invalid syntax`) |
} |
type UpgradeCharmSuccessSuite struct { |
@@ -79,7 +107,7 @@ |
c.Assert(forced, Equals, false) |
} |
-func (s *UpgradeCharmSuccessSuite) assertUpgraded(c *C, revision int, forced bool) { |
+func (s *UpgradeCharmSuccessSuite) assertUpgraded(c *C, revision int, forced bool) *charm.URL { |
err := s.riak.Refresh() |
c.Assert(err, IsNil) |
ch, force, err := s.riak.Charm() |
@@ -87,10 +115,11 @@ |
c.Assert(ch.Revision(), Equals, revision) |
c.Assert(force, Equals, forced) |
s.assertCharmUploaded(c, ch.URL()) |
+ return ch.URL() |
} |
-func (s *UpgradeCharmSuccessSuite) assertLocalRevision(c *C, revision int) { |
- dir, err := charm.ReadDir(s.path) |
+func (s *UpgradeCharmSuccessSuite) assertLocalRevision(c *C, revision int, path string) { |
+ dir, err := charm.ReadDir(path) |
c.Assert(err, IsNil) |
c.Assert(dir.Revision(), Equals, revision) |
} |
@@ -99,7 +128,7 @@ |
err := runUpgradeCharm(c, "riak") |
c.Assert(err, IsNil) |
s.assertUpgraded(c, 8, false) |
- s.assertLocalRevision(c, 8) |
+ s.assertLocalRevision(c, 8, s.path) |
} |
func (s *UpgradeCharmSuccessSuite) TestDoesntBumpRevisionWhenNotNecessary(c *C) { |
@@ -111,7 +140,7 @@ |
err = runUpgradeCharm(c, "riak") |
c.Assert(err, IsNil) |
s.assertUpgraded(c, 42, false) |
- s.assertLocalRevision(c, 42) |
+ s.assertLocalRevision(c, 42, s.path) |
} |
func (s *UpgradeCharmSuccessSuite) TestUpgradesWithBundle(c *C) { |
@@ -124,17 +153,63 @@ |
bundlePath := path.Join(s.seriesPath, "riak.charm") |
err = ioutil.WriteFile(bundlePath, buf.Bytes(), 0644) |
c.Assert(err, IsNil) |
- c.Logf("%q %q", bundlePath, s.seriesPath) |
err = runUpgradeCharm(c, "riak") |
c.Assert(err, IsNil) |
s.assertUpgraded(c, 42, false) |
- s.assertLocalRevision(c, 7) |
+ s.assertLocalRevision(c, 7, s.path) |
} |
func (s *UpgradeCharmSuccessSuite) TestForcedUpgrade(c *C) { |
err := runUpgradeCharm(c, "riak", "--force") |
c.Assert(err, IsNil) |
s.assertUpgraded(c, 8, true) |
- s.assertLocalRevision(c, 8) |
+ s.assertLocalRevision(c, 8, s.path) |
+} |
+ |
+var myriakMeta = []byte(` |
+name: myriak |
+summary: "K/V storage engine" |
+description: "Scalable K/V Store in Erlang with Clocks :-)" |
+provides: |
+ endpoint: |
+ interface: http |
+ admin: |
+ interface: http |
+peers: |
+ ring: |
+ interface: riak |
+`) |
+ |
+func (s *UpgradeCharmSuccessSuite) TestSwitch(c *C) { |
+ myriakPath := testing.Charms.RenamedClonedDirPath(s.seriesPath, "riak", "myriak") |
+ err := ioutil.WriteFile(path.Join(myriakPath, "metadata.yaml"), myriakMeta, 0644) |
+ c.Assert(err, IsNil) |
+ |
+ // Test with local repo and no explicit revsion. |
+ err = runUpgradeCharm(c, "riak", "--switch=local:myriak") |
+ c.Assert(err, IsNil) |
+ curl := s.assertUpgraded(c, 7, false) |
+ c.Assert(curl.String(), Equals, "local:precise/myriak-7") |
+ s.assertLocalRevision(c, 7, myriakPath) |
+ |
+ // Try it again without revision - should be bumped. |
+ err = runUpgradeCharm(c, "riak", "--switch=local:myriak") |
+ c.Assert(err, IsNil) |
+ curl = s.assertUpgraded(c, 8, false) |
+ c.Assert(curl.String(), Equals, "local:precise/myriak-8") |
+ s.assertLocalRevision(c, 8, myriakPath) |
+ |
+ // Now try the same with explicit revision - should fail. |
+ err = runUpgradeCharm(c, "riak", "--switch=local:myriak-8") |
+ c.Assert(err, ErrorMatches, `already running specified charm "local:precise/myriak-8"`) |
+ |
+ // Change the revision to 42 and upgrade to it with explicit revision. |
+ err = ioutil.WriteFile(path.Join(myriakPath, "revision"), []byte("42"), 0644) |
+ c.Assert(err, IsNil) |
+ err = runUpgradeCharm(c, "riak", "--switch=local:myriak-42") |
+ c.Assert(err, IsNil) |
+ curl = s.assertUpgraded(c, 42, false) |
+ c.Assert(curl.String(), Equals, "local:precise/myriak-42") |
+ s.assertLocalRevision(c, 42, myriakPath) |
} |