launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/environs/tools/marshal_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package tools_test 5 6 import ( 7 "time" 8 9 gc "launchpad.net/gocheck" 10 11 "launchpad.net/juju-core/environs/tools" 12 jc "launchpad.net/juju-core/testing/checkers" 13 ) 14 15 var _ = gc.Suite(&marshalSuite{}) 16 17 type marshalSuite struct{} 18 19 func (s *marshalSuite) TestLargeNumber(c *gc.C) { 20 metadata := []*tools.ToolsMetadata{ 21 &tools.ToolsMetadata{ 22 Release: "saucy", 23 Version: "1.2.3.4", 24 Arch: "arm", 25 Size: 9223372036854775807, 26 Path: "/somewhere/over/the/rainbow.tar.gz", 27 FileType: "tar.gz", 28 }, 29 } 30 _, products, err := tools.MarshalToolsMetadataJSON(metadata, time.Now()) 31 c.Assert(err, gc.IsNil) 32 c.Assert(string(products), jc.Contains, `"size": 9223372036854775807`) 33 } 34 35 var expectedIndex = `{ 36 "index": { 37 "com.ubuntu.juju:released:tools": { 38 "updated": "Thu, 01 Jan 1970 00:00:00 +0000", 39 "format": "products:1.0", 40 "datatype": "content-download", 41 "path": "streams/v1/com.ubuntu.juju:released:tools.json", 42 "products": [ 43 "com.ubuntu.juju:12.04:amd64", 44 "com.ubuntu.juju:12.04:arm", 45 "com.ubuntu.juju:13.10:arm" 46 ] 47 } 48 }, 49 "updated": "Thu, 01 Jan 1970 00:00:00 +0000", 50 "format": "index:1.0" 51 }` 52 53 var expectedProducts = `{ 54 "products": { 55 "com.ubuntu.juju:12.04:amd64": { 56 "version": "4.3.2.1", 57 "arch": "amd64", 58 "versions": { 59 "19700101": { 60 "items": { 61 "4.3.2.1-precise-amd64": { 62 "release": "precise", 63 "version": "4.3.2.1", 64 "arch": "amd64", 65 "size": 0, 66 "path": "whatever.tar.gz", 67 "ftype": "tar.gz", 68 "sha256": "afb14e65c794464e378def12cbad6a96f9186d69" 69 } 70 } 71 } 72 } 73 }, 74 "com.ubuntu.juju:12.04:arm": { 75 "version": "1.2.3.4", 76 "arch": "arm", 77 "versions": { 78 "19700101": { 79 "items": { 80 "1.2.3.4-precise-arm": { 81 "release": "precise", 82 "version": "1.2.3.4", 83 "arch": "arm", 84 "size": 42, 85 "path": "toenlightenment.tar.gz", 86 "ftype": "tar.gz", 87 "sha256": "" 88 } 89 } 90 } 91 } 92 }, 93 "com.ubuntu.juju:13.10:arm": { 94 "version": "1.2.3.4", 95 "arch": "arm", 96 "versions": { 97 "19700101": { 98 "items": { 99 "1.2.3.4-saucy-arm": { 100 "release": "saucy", 101 "version": "1.2.3.4", 102 "arch": "arm", 103 "size": 9223372036854775807, 104 "path": "/somewhere/over/the/rainbow.tar.gz", 105 "ftype": "tar.gz", 106 "sha256": "" 107 } 108 } 109 } 110 } 111 } 112 }, 113 "updated": "Thu, 01 Jan 1970 00:00:00 +0000", 114 "format": "products:1.0", 115 "content_id": "com.ubuntu.juju:released:tools" 116 }` 117 118 var toolMetadataForTesting = []*tools.ToolsMetadata{ 119 &tools.ToolsMetadata{ 120 Release: "saucy", 121 Version: "1.2.3.4", 122 Arch: "arm", 123 Size: 9223372036854775807, 124 Path: "/somewhere/over/the/rainbow.tar.gz", 125 FileType: "tar.gz", 126 }, 127 &tools.ToolsMetadata{ 128 Release: "precise", 129 Version: "1.2.3.4", 130 Arch: "arm", 131 Size: 42, 132 Path: "toenlightenment.tar.gz", 133 FileType: "tar.gz", 134 }, 135 &tools.ToolsMetadata{ 136 Release: "precise", 137 Version: "4.3.2.1", 138 Arch: "amd64", 139 Path: "whatever.tar.gz", 140 FileType: "tar.gz", 141 SHA256: "afb14e65c794464e378def12cbad6a96f9186d69", 142 }, 143 } 144 145 func (s *marshalSuite) TestMarshalIndex(c *gc.C) { 146 index, err := tools.MarshalToolsMetadataIndexJSON(toolMetadataForTesting, time.Unix(0, 0).UTC()) 147 c.Assert(err, gc.IsNil) 148 c.Assert(string(index), gc.Equals, expectedIndex) 149 } 150 151 func (s *marshalSuite) TestMarshalProducts(c *gc.C) { 152 products, err := tools.MarshalToolsMetadataProductsJSON(toolMetadataForTesting, time.Unix(0, 0).UTC()) 153 c.Assert(err, gc.IsNil) 154 c.Assert(string(products), gc.Equals, expectedProducts) 155 } 156 157 func (s *marshalSuite) TestMarshal(c *gc.C) { 158 index, products, err := tools.MarshalToolsMetadataJSON(toolMetadataForTesting, time.Unix(0, 0).UTC()) 159 c.Assert(err, gc.IsNil) 160 c.Assert(string(index), gc.Equals, expectedIndex) 161 c.Assert(string(products), gc.Equals, expectedProducts) 162 }