Example #1
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
}
Example #2
0
File: testing.go Project: bac/juju
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
}