Left: | ||
Right: |
OLD | NEW |
---|---|
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 err = runUpgradeCharm(c, "riak") | 57 err = runUpgradeCharm(c, "riak") |
58 c.Assert(err, ErrorMatches, `already running latest charm "local:precise /riak-7"`) | 58 c.Assert(err, ErrorMatches, `already running latest charm "local:precise /riak-7"`) |
59 } | 59 } |
60 | 60 |
61 func (s *UpgradeCharmErrorsSuite) TestInvalidSwitchURL(c *C) { | |
62 testing.Charms.ClonedDirPath(s.seriesPath, "riak") | |
63 err := runDeploy(c, "local:riak", "riak") | |
64 c.Assert(err, IsNil) | |
65 | |
66 err = runUpgradeCharm(c, "riak", "--switch=blah") | |
67 c.Assert(err, ErrorMatches, "charm not found: cs:precise/blah") | |
68 err = runUpgradeCharm(c, "riak", "--switch=cs:missing/one-1") | |
69 c.Assert(err, ErrorMatches, "charm not found: cs:missing/one") | |
70 // TODO(dimitern): add tests with incompatible charms | |
71 } | |
72 | |
61 type UpgradeCharmSuccessSuite struct { | 73 type UpgradeCharmSuccessSuite struct { |
62 repoSuite | 74 repoSuite |
63 path string | 75 path string |
64 riak *state.Service | 76 riak *state.Service |
65 } | 77 } |
66 | 78 |
67 var _ = Suite(&UpgradeCharmSuccessSuite{}) | 79 var _ = Suite(&UpgradeCharmSuccessSuite{}) |
68 | 80 |
69 func (s *UpgradeCharmSuccessSuite) SetUpTest(c *C) { | 81 func (s *UpgradeCharmSuccessSuite) SetUpTest(c *C) { |
70 s.repoSuite.SetUpTest(c) | 82 s.repoSuite.SetUpTest(c) |
71 s.path = testing.Charms.ClonedDirPath(s.seriesPath, "riak") | 83 s.path = testing.Charms.ClonedDirPath(s.seriesPath, "riak") |
72 err := runDeploy(c, "local:riak", "riak") | 84 err := runDeploy(c, "local:riak", "riak") |
73 c.Assert(err, IsNil) | 85 c.Assert(err, IsNil) |
74 s.riak, err = s.State.Service("riak") | 86 s.riak, err = s.State.Service("riak") |
75 c.Assert(err, IsNil) | 87 c.Assert(err, IsNil) |
76 ch, forced, err := s.riak.Charm() | 88 ch, forced, err := s.riak.Charm() |
77 c.Assert(err, IsNil) | 89 c.Assert(err, IsNil) |
78 c.Assert(ch.Revision(), Equals, 7) | 90 c.Assert(ch.Revision(), Equals, 7) |
79 c.Assert(forced, Equals, false) | 91 c.Assert(forced, Equals, false) |
80 } | 92 } |
81 | 93 |
82 func (s *UpgradeCharmSuccessSuite) assertUpgraded(c *C, revision int, forced boo l) { | 94 func (s *UpgradeCharmSuccessSuite) assertUpgraded(c *C, revision int, forced boo l, curl *charm.URL) { |
fwereade
2013/04/25 15:09:06
I'd rather return the charm url and assert it in t
dimitern
2013/04/25 15:29:01
Good point, will do.
| |
83 err := s.riak.Refresh() | 95 err := s.riak.Refresh() |
84 c.Assert(err, IsNil) | 96 c.Assert(err, IsNil) |
85 ch, force, err := s.riak.Charm() | 97 ch, force, err := s.riak.Charm() |
86 c.Assert(err, IsNil) | 98 c.Assert(err, IsNil) |
87 c.Assert(ch.Revision(), Equals, revision) | 99 c.Assert(ch.Revision(), Equals, revision) |
88 c.Assert(force, Equals, forced) | 100 c.Assert(force, Equals, forced) |
89 s.assertCharmUploaded(c, ch.URL()) | 101 s.assertCharmUploaded(c, ch.URL()) |
102 if curl != nil { | |
103 c.Assert(ch.URL().String(), Equals, curl.String()) | |
104 } | |
90 } | 105 } |
91 | 106 |
92 func (s *UpgradeCharmSuccessSuite) assertLocalRevision(c *C, revision int) { | 107 func (s *UpgradeCharmSuccessSuite) assertLocalRevision(c *C, revision int, path string) { |
TheMue
2013/04/25 14:40:06
Maybe I'm only blind or it is planned for later, b
dimitern
2013/04/25 15:29:01
Only in the last test case path != s.path.
| |
93 » dir, err := charm.ReadDir(s.path) | 108 » dir, err := charm.ReadDir(path) |
94 c.Assert(err, IsNil) | 109 c.Assert(err, IsNil) |
95 c.Assert(dir.Revision(), Equals, revision) | 110 c.Assert(dir.Revision(), Equals, revision) |
96 } | 111 } |
97 | 112 |
98 func (s *UpgradeCharmSuccessSuite) TestBumpsRevisionWhenNecessary(c *C) { | 113 func (s *UpgradeCharmSuccessSuite) TestBumpsRevisionWhenNecessary(c *C) { |
99 err := runUpgradeCharm(c, "riak") | 114 err := runUpgradeCharm(c, "riak") |
100 c.Assert(err, IsNil) | 115 c.Assert(err, IsNil) |
101 » s.assertUpgraded(c, 8, false) | 116 » s.assertUpgraded(c, 8, false, nil) |
102 » s.assertLocalRevision(c, 8) | 117 » s.assertLocalRevision(c, 8, s.path) |
103 } | 118 } |
104 | 119 |
105 func (s *UpgradeCharmSuccessSuite) TestDoesntBumpRevisionWhenNotNecessary(c *C) { | 120 func (s *UpgradeCharmSuccessSuite) TestDoesntBumpRevisionWhenNotNecessary(c *C) { |
106 dir, err := charm.ReadDir(s.path) | 121 dir, err := charm.ReadDir(s.path) |
107 c.Assert(err, IsNil) | 122 c.Assert(err, IsNil) |
108 err = dir.SetDiskRevision(42) | 123 err = dir.SetDiskRevision(42) |
109 c.Assert(err, IsNil) | 124 c.Assert(err, IsNil) |
110 | 125 |
111 err = runUpgradeCharm(c, "riak") | 126 err = runUpgradeCharm(c, "riak") |
112 c.Assert(err, IsNil) | 127 c.Assert(err, IsNil) |
113 » s.assertUpgraded(c, 42, false) | 128 » s.assertUpgraded(c, 42, false, nil) |
114 » s.assertLocalRevision(c, 42) | 129 » s.assertLocalRevision(c, 42, s.path) |
115 } | 130 } |
116 | 131 |
117 func (s *UpgradeCharmSuccessSuite) TestUpgradesWithBundle(c *C) { | 132 func (s *UpgradeCharmSuccessSuite) TestUpgradesWithBundle(c *C) { |
118 dir, err := charm.ReadDir(s.path) | 133 dir, err := charm.ReadDir(s.path) |
119 c.Assert(err, IsNil) | 134 c.Assert(err, IsNil) |
120 dir.SetRevision(42) | 135 dir.SetRevision(42) |
121 buf := &bytes.Buffer{} | 136 buf := &bytes.Buffer{} |
122 err = dir.BundleTo(buf) | 137 err = dir.BundleTo(buf) |
123 c.Assert(err, IsNil) | 138 c.Assert(err, IsNil) |
124 bundlePath := path.Join(s.seriesPath, "riak.charm") | 139 bundlePath := path.Join(s.seriesPath, "riak.charm") |
125 err = ioutil.WriteFile(bundlePath, buf.Bytes(), 0644) | 140 err = ioutil.WriteFile(bundlePath, buf.Bytes(), 0644) |
126 c.Assert(err, IsNil) | 141 c.Assert(err, IsNil) |
127 c.Logf("%q %q", bundlePath, s.seriesPath) | 142 c.Logf("%q %q", bundlePath, s.seriesPath) |
128 | 143 |
129 err = runUpgradeCharm(c, "riak") | 144 err = runUpgradeCharm(c, "riak") |
130 c.Assert(err, IsNil) | 145 c.Assert(err, IsNil) |
131 » s.assertUpgraded(c, 42, false) | 146 » s.assertUpgraded(c, 42, false, nil) |
132 » s.assertLocalRevision(c, 7) | 147 » s.assertLocalRevision(c, 7, s.path) |
133 } | 148 } |
134 | 149 |
135 func (s *UpgradeCharmSuccessSuite) TestForcedUpgrade(c *C) { | 150 func (s *UpgradeCharmSuccessSuite) TestForcedUpgrade(c *C) { |
136 err := runUpgradeCharm(c, "riak", "--force") | 151 err := runUpgradeCharm(c, "riak", "--force") |
137 c.Assert(err, IsNil) | 152 c.Assert(err, IsNil) |
138 » s.assertUpgraded(c, 8, true) | 153 » s.assertUpgraded(c, 8, true, nil) |
139 » s.assertLocalRevision(c, 8) | 154 » s.assertLocalRevision(c, 8, s.path) |
140 } | 155 } |
156 | |
157 var myriakMeta = []byte(` | |
158 name: myriak | |
159 summary: "K/V storage engine" | |
160 description: "Scalable K/V Store in Erlang with Clocks :-)" | |
161 provides: | |
162 endpoint: | |
163 interface: http | |
164 admin: | |
165 interface: http | |
166 peers: | |
167 ring: | |
168 interface: riak | |
169 `) | |
170 | |
171 func (s *UpgradeCharmSuccessSuite) TestSwitch(c *C) { | |
172 myriakPath := testing.Charms.RenamedClonedDirPath(s.seriesPath, "riak", "myriak") | |
173 err := ioutil.WriteFile(path.Join(myriakPath, "metadata.yaml"), myriakMe ta, 0644) | |
174 c.Assert(err, IsNil) | |
175 | |
176 err = runUpgradeCharm(c, "riak", "--switch=local:myriak") | |
177 c.Assert(err, IsNil) | |
178 s.assertUpgraded(c, 7, false, charm.MustParseURL("local:precise/myriak-7 ")) | |
179 s.assertLocalRevision(c, 7, myriakPath) | |
rog
2013/04/25 14:43:52
also test switching from one cs: charm to another?
fwereade
2013/04/25 15:09:06
We have thus far gone with the shared agreement th
dimitern
2013/04/25 15:29:01
Sorry, I have no clue how to test this - ideas?
fwereade
2013/04/25 15:43:30
I'd be fine with setting charm.Store to some other
dimitern
2013/04/26 14:29:01
Not sure how to do that either - it seems I have t
| |
180 } | |
OLD | NEW |