~nskaggs/+junk/xenial-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-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

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