launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/environs/imagemetadata/marshal_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package imagemetadata_test 5 6 import ( 7 "time" 8 9 gc "launchpad.net/gocheck" 10 11 "launchpad.net/juju-core/environs/imagemetadata" 12 "launchpad.net/juju-core/environs/simplestreams" 13 "launchpad.net/juju-core/testing/testbase" 14 ) 15 16 var _ = gc.Suite(&marshalSuite{}) 17 18 type marshalSuite struct { 19 testbase.LoggingSuite 20 } 21 22 var expectedIndex = `{ 23 "index": { 24 "com.ubuntu.cloud:custom": { 25 "updated": "Thu, 01 Jan 1970 00:00:00 +0000", 26 "format": "products:1.0", 27 "datatype": "image-ids", 28 "cloudname": "custom", 29 "clouds": [ 30 { 31 "region": "region", 32 "endpoint": "endpoint" 33 } 34 ], 35 "path": "streams/v1/com.ubuntu.cloud:released:imagemetadata.json", 36 "products": [ 37 "com.ubuntu.cloud:server:12.04:amd64", 38 "com.ubuntu.cloud:server:12.04:arm", 39 "com.ubuntu.cloud:server:13.10:arm" 40 ] 41 } 42 }, 43 "updated": "Thu, 01 Jan 1970 00:00:00 +0000", 44 "format": "index:1.0" 45 }` 46 47 var expectedProducts = `{ 48 "products": { 49 "com.ubuntu.cloud:server:12.04:amd64": { 50 "version": "12.04", 51 "arch": "amd64", 52 "versions": { 53 "19700101": { 54 "items": { 55 "abcd": { 56 "id": "abcd" 57 } 58 } 59 } 60 } 61 }, 62 "com.ubuntu.cloud:server:12.04:arm": { 63 "version": "12.04", 64 "arch": "arm", 65 "versions": { 66 "19700101": { 67 "items": { 68 "5678": { 69 "id": "5678" 70 } 71 } 72 } 73 } 74 }, 75 "com.ubuntu.cloud:server:13.10:arm": { 76 "version": "13.10", 77 "arch": "arm", 78 "versions": { 79 "19700101": { 80 "items": { 81 "1234": { 82 "id": "1234" 83 } 84 } 85 } 86 } 87 } 88 }, 89 "updated": "Thu, 01 Jan 1970 00:00:00 +0000", 90 "format": "products:1.0", 91 "content_id": "com.ubuntu.cloud:custom" 92 }` 93 94 var imageMetadataForTesting = []*imagemetadata.ImageMetadata{ 95 &imagemetadata.ImageMetadata{ 96 Id: "1234", 97 Version: "13.10", 98 Arch: "arm", 99 }, 100 &imagemetadata.ImageMetadata{ 101 Id: "5678", 102 Version: "12.04", 103 Arch: "arm", 104 }, 105 &imagemetadata.ImageMetadata{ 106 Id: "abcd", 107 Version: "12.04", 108 Arch: "amd64", 109 }, 110 } 111 112 func (s *marshalSuite) TestMarshalIndex(c *gc.C) { 113 cloudSpec := []simplestreams.CloudSpec{{Region: "region", Endpoint: "endpoint"}} 114 index, err := imagemetadata.MarshalImageMetadataIndexJSON(imageMetadataForTesting, cloudSpec, time.Unix(0, 0).UTC()) 115 c.Assert(err, gc.IsNil) 116 c.Assert(string(index), gc.Equals, expectedIndex) 117 } 118 119 func (s *marshalSuite) TestMarshalProducts(c *gc.C) { 120 products, err := imagemetadata.MarshalImageMetadataProductsJSON(imageMetadataForTesting, time.Unix(0, 0).UTC()) 121 c.Assert(err, gc.IsNil) 122 c.Assert(string(products), gc.Equals, expectedProducts) 123 } 124 125 func (s *marshalSuite) TestMarshal(c *gc.C) { 126 cloudSpec := []simplestreams.CloudSpec{{Region: "region", Endpoint: "endpoint"}} 127 index, products, err := imagemetadata.MarshalImageMetadataJSON(imageMetadataForTesting, cloudSpec, time.Unix(0, 0).UTC()) 128 c.Assert(err, gc.IsNil) 129 c.Assert(string(index), gc.Equals, expectedIndex) 130 c.Assert(string(products), gc.Equals, expectedProducts) 131 }