func (*metadataHelperSuite) TestResolveMetadata(c *gc.C) { var versionStrings = []string{"1.2.3-precise-amd64"} dir := c.MkDir() ttesting.MakeTools(c, dir, "releases", versionStrings) toolsList := coretools.List{{ Version: version.MustParseBinary(versionStrings[0]), Size: 123, SHA256: "abc", }} stor, err := filestorage.NewFileStorageReader(dir) c.Assert(err, gc.IsNil) err = tools.ResolveMetadata(stor, nil) c.Assert(err, gc.IsNil) // We already have size/sha256, so ensure that storage isn't consulted. countingStorage := &countingStorage{StorageReader: stor} metadata := tools.MetadataFromTools(toolsList) err = tools.ResolveMetadata(countingStorage, metadata) c.Assert(err, gc.IsNil) c.Assert(countingStorage.counter, gc.Equals, 0) // Now clear size/sha256, and check that it is called, and // the size/sha256 sum are updated. metadata[0].Size = 0 metadata[0].SHA256 = "" err = tools.ResolveMetadata(countingStorage, metadata) c.Assert(err, gc.IsNil) c.Assert(countingStorage.counter, gc.Equals, 1) c.Assert(metadata[0].Size, gc.Not(gc.Equals), 0) c.Assert(metadata[0].SHA256, gc.Not(gc.Equals), "") }
// This is essentially the same as tools.MergeAndWriteMetadata, but also // resolves metadata for existing tools by fetching them and computing // size/sha256 locally. func mergeAndWriteMetadata(stor storage.Storage, toolsList coretools.List, writeMirrors envtools.ShouldWriteMirrors) error { existing, err := envtools.ReadMetadata(stor) if err != nil { return err } metadata := envtools.MetadataFromTools(toolsList) if metadata, err = envtools.MergeMetadata(metadata, existing); err != nil { return err } if err = envtools.ResolveMetadata(stor, metadata); err != nil { return err } return envtools.WriteMetadata(stor, metadata, writeMirrors) }