~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/launchpad.net/goose/nova/json_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package nova_test
 
2
 
 
3
import (
 
4
        "encoding/json"
 
5
        . "launchpad.net/gocheck"
 
6
        "launchpad.net/goose/nova"
 
7
)
 
8
 
 
9
type JsonSuite struct {
 
10
}
 
11
 
 
12
var _ = Suite(&JsonSuite{})
 
13
 
 
14
func (s *JsonSuite) SetUpSuite(c *C) {
 
15
        nova.UseNumericIds(true)
 
16
}
 
17
 
 
18
func (s *JsonSuite) assertMarshallRoundtrip(c *C, value interface{}, unmarshalled interface{}) {
 
19
        data, err := json.Marshal(value)
 
20
        if err != nil {
 
21
                panic(err)
 
22
        }
 
23
        err = json.Unmarshal(data, &unmarshalled)
 
24
        if err != nil {
 
25
                panic(err)
 
26
        }
 
27
        c.Assert(unmarshalled, DeepEquals, value)
 
28
}
 
29
 
 
30
// The following tests all check that unmarshalling of Ids with values > 1E6
 
31
// works properly.
 
32
 
 
33
func (s *JsonSuite) TestMarshallEntityLargeIntId(c *C) {
 
34
        entity := nova.Entity{Id: "2000000", Name: "test"}
 
35
        var unmarshalled nova.Entity
 
36
        s.assertMarshallRoundtrip(c, &entity, &unmarshalled)
 
37
}
 
38
 
 
39
func (s *JsonSuite) TestMarshallFlavorDetailLargeIntId(c *C) {
 
40
        fd := nova.FlavorDetail{Id: "2000000", Name: "test"}
 
41
        var unmarshalled nova.FlavorDetail
 
42
        s.assertMarshallRoundtrip(c, &fd, &unmarshalled)
 
43
}
 
44
 
 
45
func (s *JsonSuite) TestMarshallServerDetailLargeIntId(c *C) {
 
46
        fd := nova.Entity{Id: "2000000", Name: "test"}
 
47
        im := nova.Entity{Id: "2000000", Name: "test"}
 
48
        sd := nova.ServerDetail{Id: "2000000", Name: "test", Flavor: fd, Image: im}
 
49
        var unmarshalled nova.ServerDetail
 
50
        s.assertMarshallRoundtrip(c, &sd, &unmarshalled)
 
51
}
 
52
 
 
53
func (s *JsonSuite) TestMarshallFloatingIPLargeIntId(c *C) {
 
54
        id := "3000000"
 
55
        fip := nova.FloatingIP{Id: 2000000, InstanceId: &id}
 
56
        var unmarshalled nova.FloatingIP
 
57
        s.assertMarshallRoundtrip(c, &fip, &unmarshalled)
 
58
}