~nskaggs/+junk/juju-packaging-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/environs/simplestreams/json_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-27 20:23:11 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161027202311-sux4jk2o73p1d6rg
Re-add src

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package simplestreams_test
 
2
 
 
3
import (
 
4
        "encoding/json"
 
5
 
 
6
        jc "github.com/juju/testing/checkers"
 
7
        gc "gopkg.in/check.v1"
 
8
 
 
9
        "github.com/juju/juju/environs/simplestreams"
 
10
)
 
11
 
 
12
type jsonSuite struct{}
 
13
 
 
14
func (s *jsonSuite) TestItemCollectionMarshalling(c *gc.C) {
 
15
        // Ensure that unmarshalling a simplestreams.ItemCollection
 
16
        // directly (not through ParseCloudMetadata) doesn't
 
17
        // cause any surprises.
 
18
        var m simplestreams.ItemCollection
 
19
        m.Items = make(map[string]interface{})
 
20
        err := json.Unmarshal([]byte(`{
 
21
        "items": {
 
22
            "a": "b",
 
23
            "c": 123 
 
24
        }
 
25
    }`), &m)
 
26
        c.Assert(err, jc.ErrorIsNil)
 
27
        c.Assert(m.Items, gc.DeepEquals, map[string]interface{}{
 
28
                "a": "b",
 
29
                "c": float64(123),
 
30
        })
 
31
        // Ensure marshalling works as expected, too.
 
32
        b, err := json.Marshal(&m)
 
33
        c.Assert(err, jc.ErrorIsNil)
 
34
        c.Assert(string(b), gc.Equals, `{"items":{"a":"b","c":123}}`)
 
35
}