~ubuntu-branches/ubuntu/trusty/juju-core/trusty

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/version/version_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-03-24 16:05:44 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20140324160544-g8lsfufby18d5fj4
Tags: 1.17.6-0ubuntu1
* New upstream point release, including fixes for:
  - br0 not bought up by cloud-init with MAAS provider (LP: #1271144).
  - ppc64el enablement for juju/lxc (LP: #1273769).
  - juju userdata should not restart networking (LP: #1248283).
  - error detecting hardware characteristics (LP: #1276909).
  - juju instances not including the default security group (LP: #1129720).
  - juju bootstrap does not honor https_proxy (LP: #1240260).
* d/control,rules: Drop BD on bash-completion, install bash-completion
  direct from upstream source code.
* d/rules: Set HOME prior to generating man pages.
* d/control: Drop alternative dependency on mongodb-server; juju now only
  works on trusty with juju-mongodb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "encoding/json"
 
8
        "io/ioutil"
 
9
        "path/filepath"
8
10
        "strings"
9
11
        "testing"
10
12
 
11
13
        "labix.org/v2/mgo/bson"
12
14
        gc "launchpad.net/gocheck"
 
15
        "launchpad.net/goyaml"
13
16
 
 
17
        "launchpad.net/juju-core/testing/testbase"
14
18
        "launchpad.net/juju-core/version"
15
19
)
16
20
 
17
 
type suite struct{}
 
21
type suite struct {
 
22
        testbase.LoggingSuite
 
23
}
18
24
 
19
 
var _ = gc.Suite(suite{})
 
25
var _ = gc.Suite(&suite{})
20
26
 
21
27
func Test(t *testing.T) {
22
28
        gc.TestingT(t)
43
49
        {"2.0.1.10", "2.0.0.0", 1},
44
50
}
45
51
 
46
 
func (suite) TestCompare(c *gc.C) {
 
52
func (*suite) TestCompare(c *gc.C) {
47
53
        for i, test := range cmpTests {
48
54
                c.Logf("test %d", i)
49
55
                v1, err := version.Parse(test.v1)
105
111
        err: "invalid version.*",
106
112
}}
107
113
 
108
 
func (suite) TestParse(c *gc.C) {
 
114
func (*suite) TestParse(c *gc.C) {
109
115
        for i, test := range parseTests {
110
116
                c.Logf("test %d", i)
111
117
                got, err := version.Parse(test.v)
151
157
        err: "invalid binary version.*",
152
158
}}
153
159
 
154
 
func (suite) TestParseBinary(c *gc.C) {
 
160
func (*suite) TestParseBinary(c *gc.C) {
155
161
        for i, test := range parseBinaryTests {
156
162
                c.Logf("test 1: %d", i)
157
163
                got, err := version.ParseBinary(test.v)
194
200
        "bson",
195
201
        bson.Marshal,
196
202
        bson.Unmarshal,
 
203
}, {
 
204
        "yaml",
 
205
        goyaml.Marshal,
 
206
        goyaml.Unmarshal,
197
207
}}
198
208
 
199
 
func (suite) TestBinaryMarshalUnmarshal(c *gc.C) {
 
209
func (*suite) TestBinaryMarshalUnmarshal(c *gc.C) {
200
210
        for _, m := range marshallers {
201
211
                c.Logf("encoding %v", m.name)
202
212
                type doc struct {
203
 
                        Version version.Binary
 
213
                        Version *version.Binary
204
214
                }
205
 
                v := doc{version.MustParseBinary("1.2.3-foo-bar")}
206
 
                data, err := m.marshal(v)
207
 
                c.Assert(err, gc.IsNil)
208
 
                var nv doc
209
 
                err = m.unmarshal(data, &nv)
210
 
                c.Assert(err, gc.IsNil)
211
 
                c.Assert(v, gc.Equals, nv)
 
215
                // Work around goyaml bug #1096149
 
216
                // SetYAML is not called for non-pointer fields.
 
217
                bp := version.MustParseBinary("1.2.3-foo-bar")
 
218
                v := doc{&bp}
 
219
                data, err := m.marshal(&v)
 
220
                c.Assert(err, gc.IsNil)
 
221
                var bv doc
 
222
                err = m.unmarshal(data, &bv)
 
223
                c.Assert(err, gc.IsNil)
 
224
                c.Assert(bv, gc.DeepEquals, v)
212
225
        }
213
226
}
214
227
 
215
 
func (suite) TestNumberMarshalUnmarshal(c *gc.C) {
 
228
func (*suite) TestNumberMarshalUnmarshal(c *gc.C) {
216
229
        for _, m := range marshallers {
217
230
                c.Logf("encoding %v", m.name)
218
231
                type doc struct {
219
 
                        Version version.Number
 
232
                        Version *version.Number
220
233
                }
221
 
                v := doc{version.MustParse("1.2.3")}
 
234
                // Work around goyaml bug #1096149
 
235
                // SetYAML is not called for non-pointer fields.
 
236
                np := version.MustParse("1.2.3")
 
237
                v := doc{&np}
222
238
                data, err := m.marshal(&v)
223
239
                c.Assert(err, gc.IsNil)
224
240
                var nv doc
225
241
                err = m.unmarshal(data, &nv)
226
242
                c.Assert(err, gc.IsNil)
227
 
                c.Assert(v, gc.Equals, nv)
 
243
                c.Assert(nv, gc.DeepEquals, v)
228
244
        }
229
245
}
230
246
 
249
265
        err: `invalid major version number blah: strconv.ParseInt: parsing "blah": invalid syntax`,
250
266
}}
251
267
 
252
 
func (suite) TestParseMajorMinor(c *gc.C) {
 
268
func (*suite) TestParseMajorMinor(c *gc.C) {
253
269
        for i, test := range parseMajorMinorTests {
254
270
                c.Logf("test %d", i)
255
271
                major, minor, err := version.ParseMajorMinor(test.v)
262
278
                }
263
279
        }
264
280
}
 
281
 
 
282
func (s *suite) TestUseFastLXC(c *gc.C) {
 
283
        for i, test := range []struct {
 
284
                message        string
 
285
                releaseContent string
 
286
                expected       string
 
287
        }{{
 
288
                message: "missing release file",
 
289
        }, {
 
290
                message:        "missing prefix in file",
 
291
                releaseContent: "some junk\nand more junk",
 
292
        }, {
 
293
                message: "precise release",
 
294
                releaseContent: `
 
295
DISTRIB_ID=Ubuntu
 
296
DISTRIB_RELEASE=12.04
 
297
DISTRIB_CODENAME=precise
 
298
DISTRIB_DESCRIPTION="Ubuntu 12.04.3 LTS"
 
299
`,
 
300
                expected: "12.04",
 
301
        }, {
 
302
                message: "trusty release",
 
303
                releaseContent: `
 
304
DISTRIB_ID=Ubuntu
 
305
DISTRIB_RELEASE=14.04
 
306
DISTRIB_CODENAME=trusty
 
307
DISTRIB_DESCRIPTION="Ubuntu Trusty Tahr (development branch)"
 
308
`,
 
309
                expected: "14.04",
 
310
        }, {
 
311
                message:        "minimal trusty release",
 
312
                releaseContent: `DISTRIB_RELEASE=14.04`,
 
313
                expected:       "14.04",
 
314
        }, {
 
315
                message:        "minimal unstable unicorn",
 
316
                releaseContent: `DISTRIB_RELEASE=14.10`,
 
317
                expected:       "14.10",
 
318
        }, {
 
319
                message:        "minimal jaunty",
 
320
                releaseContent: `DISTRIB_RELEASE=9.10`,
 
321
                expected:       "9.10",
 
322
        }} {
 
323
                c.Logf("%v: %v", i, test.message)
 
324
                filename := filepath.Join(c.MkDir(), "lsbRelease")
 
325
                s.PatchValue(version.LSBReleaseFileVar, filename)
 
326
                if test.releaseContent != "" {
 
327
                        err := ioutil.WriteFile(filename, []byte(test.releaseContent+"\n"), 0644)
 
328
                        c.Assert(err, gc.IsNil)
 
329
                }
 
330
                value := version.ReleaseVersion()
 
331
                c.Assert(value, gc.Equals, test.expected)
 
332
        }
 
333
}