Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(514)

Side by Side Diff: environs/tools_test.go

Issue 6260048: environs: read series from /etc/lsb-release
Patch Set: environs: read series from /etc/lsb-release Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« environs/tools.go ('K') | « environs/tools.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package environs_test 1 package environs_test
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "io/ioutil" 5 "io/ioutil"
6 . "launchpad.net/gocheck" 6 . "launchpad.net/gocheck"
7 "launchpad.net/juju/go/environs" 7 "launchpad.net/juju/go/environs"
8 "launchpad.net/juju/go/environs/dummy" 8 "launchpad.net/juju/go/environs/dummy"
9 "launchpad.net/juju/go/version" 9 "launchpad.net/juju/go/version"
10 "net/http" 10 "net/http"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 c.Assert(err, IsNil) 227 c.Assert(err, IsNil)
228 resp, err := http.Get(url) 228 resp, err := http.Get(url)
229 c.Assert(err, IsNil) 229 c.Assert(err, IsNil)
230 data, err := ioutil.ReadAll(resp.Body) 230 data, err := ioutil.ReadAll(resp.Body)
231 c.Assert(err, IsNil) 231 c.Assert(err, IsNil)
232 c.Assert(string(data), Equals, tt.expect, Commentf("url %s", url)) 232 c.Assert(string(data), Equals, tt.expect, Commentf("url %s", url))
233 } 233 }
234 t.env.Destroy(nil) 234 t.env.Destroy(nil)
235 } 235 }
236 } 236 }
237
238 var readSeriesTests = []struct {
239 contents string
240 series string
241 }{{
242 `DISTRIB_ID=Ubuntu
243 DISTRIB_RELEASE=12.04
244 DISTRIB_CODENAME=precise
245 DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"`,
246 "precise",
247 }, {
248 "DISTRIB_CODENAME=\tprecise\t",
249 "precise",
250 }, {
251 `DISTRIB_ID=Ubuntu
252 DISTRIB_RELEASE=12.10
253 DISTRIB_CODENAME=quantal
254 DISTRIB_DESCRIPTION="Ubuntu 12.10"`,
255 "quantal",
256 }, {
257 "",
258 "unknownSeries",
259 },
260 }
261
262 func (t *ToolsSuite) TestReadSeries(c *C) {
263 d := c.MkDir()
264 f := filepath.Join(d, "foo")
265 for i, t := range readSeriesTests {
266 c.Logf("test %d", i)
267 err := ioutil.WriteFile(f, []byte(t.contents), 0666)
268 c.Assert(err, IsNil)
269 c.Assert(environs.ReadSeries(f), Equals, t.series)
270 }
271 }
272
273 func (t *ToolsSuite) TestCurrentSeries(c *C) {
274 s := environs.CurrentSeries
275 if s == "unknownSeries" {
276 s = "n/a"
niemeyer 2012/05/29 12:28:41 Huh.. why!?
277 }
278 out, err := exec.Command("lsb_release", "-c").CombinedOutput()
279 if err != nil {
280 c.Assert(s, Equals, "n/a")
281 } else {
282 c.Assert(string(out), Equals, "Codename:\t"+s+"\n")
283 }
284 }
OLDNEW
« environs/tools.go ('K') | « environs/tools.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 204d58d