Beispiel #1
0
func (s *marshalSuite) TestMarshal(c *gc.C) {
	index, legacyIndex, products, err := tools.MarshalToolsMetadataJSON(s.streamMetadata, time.Unix(0, 0).UTC())
	c.Assert(err, jc.ErrorIsNil)
	assertIndex(c, index, expectedIndex)
	assertIndex(c, legacyIndex, expectedLegacyIndex)
	assertProducts(c, products)
}
Beispiel #2
0
func generateMetadata(c *gc.C, stream string, versions ...version.Binary) []metadataFile {
	var metadata = make([]*tools.ToolsMetadata, len(versions))
	for i, vers := range versions {
		basePath := fmt.Sprintf("%s/tools-%s.tar.gz", stream, vers.String())
		metadata[i] = &tools.ToolsMetadata{
			Release: vers.Series,
			Version: vers.Number.String(),
			Arch:    vers.Arch,
			Path:    basePath,
		}
	}
	var streamMetadata = map[string][]*tools.ToolsMetadata{
		stream: metadata,
	}
	index, legacyIndex, products, err := tools.MarshalToolsMetadataJSON(streamMetadata, time.Now())
	c.Assert(err, jc.ErrorIsNil)
	objects := []metadataFile{
		{simplestreams.UnsignedIndex("v1", 2), index},
	}
	if stream == "released" {
		objects = append(objects, metadataFile{simplestreams.UnsignedIndex("v1", 1), legacyIndex})
	}
	for stream, metadata := range products {
		objects = append(objects, metadataFile{tools.ProductMetadataPath(stream), metadata})
	}
	return objects
}
Beispiel #3
0
func (s *marshalSuite) TestMarshalNoReleaseStream(c *gc.C) {
	metadata := s.streamMetadata
	delete(metadata, "released")
	index, legacyIndex, products, err := tools.MarshalToolsMetadataJSON(s.streamMetadata, time.Unix(0, 0).UTC())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(legacyIndex, gc.IsNil)
	c.Assert(index, gc.NotNil)
	c.Assert(products, gc.NotNil)
}
Beispiel #4
0
func (s *marshalSuite) TestLargeNumber(c *gc.C) {
	metadata := []*tools.ToolsMetadata{
		&tools.ToolsMetadata{
			Release:  "saucy",
			Version:  "1.2.3.4",
			Arch:     "arm",
			Size:     9223372036854775807,
			Path:     "/somewhere/over/the/rainbow.tar.gz",
			FileType: "tar.gz",
		},
	}
	_, products, err := tools.MarshalToolsMetadataJSON(metadata, time.Now())
	c.Assert(err, gc.IsNil)
	c.Assert(string(products), jc.Contains, `"size": 9223372036854775807`)
}
Beispiel #5
0
func generateMetadata(c *gc.C, versions ...version.Binary) []metadataFile {
	var metadata = make([]*tools.ToolsMetadata, len(versions))
	for i, vers := range versions {
		basePath := fmt.Sprintf("releases/tools-%s.tar.gz", vers.String())
		metadata[i] = &tools.ToolsMetadata{
			Release: vers.Series,
			Version: vers.Number.String(),
			Arch:    vers.Arch,
			Path:    basePath,
		}
	}
	index, products, err := tools.MarshalToolsMetadataJSON(metadata, time.Now())
	c.Assert(err, gc.IsNil)
	objects := []metadataFile{
		{simplestreams.UnsignedIndex, index},
		{tools.ProductMetadataPath, products},
	}
	return objects
}
Beispiel #6
0
func generateMetadata(c *gc.C, stream string, versions ...version.Binary) []metadataFile {
	var metadata = make([]*tools.ToolsMetadata, len(versions))
	for i, vers := range versions {
		basePath := fmt.Sprintf("%s/tools-%s.tar.gz", stream, vers.String())
		metadata[i] = &tools.ToolsMetadata{
			Release: vers.Series,
			Version: vers.Number.String(),
			Arch:    vers.Arch,
			Path:    basePath,
		}
	}
	var streamMetadata = map[string][]*tools.ToolsMetadata{
		stream: metadata,
	}
	// TODO(perrito666) 2016-05-02 lp:1558657
	index, legacyIndex, products, err := tools.MarshalToolsMetadataJSON(streamMetadata, time.Now())
	c.Assert(err, jc.ErrorIsNil)

	objects := []metadataFile{}
	addTools := func(fileName string, content []byte) {
		// add unsigned
		objects = append(objects, metadataFile{fileName, content})

		signedFilename, signedContent, err := sstesting.SignMetadata(fileName, content)
		c.Assert(err, jc.ErrorIsNil)

		// add signed
		objects = append(objects, metadataFile{signedFilename, signedContent})
	}

	addTools(simplestreams.UnsignedIndex("v1", 2), index)
	if stream == "released" {
		addTools(simplestreams.UnsignedIndex("v1", 1), legacyIndex)
	}
	for stream, metadata := range products {
		addTools(tools.ProductMetadataPath(stream), metadata)
	}
	return objects
}
Beispiel #7
0
func (s *marshalSuite) TestMarshal(c *gc.C) {
	index, products, err := tools.MarshalToolsMetadataJSON(toolMetadataForTesting, time.Unix(0, 0).UTC())
	c.Assert(err, gc.IsNil)
	c.Assert(string(index), gc.Equals, expectedIndex)
	c.Assert(string(products), gc.Equals, expectedProducts)
}