launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/environs/simplestreams/json_test.go (about)

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