func assertSourceContents(c *gc.C, source simplestreams.DataSource, filename string, content []byte) { rc, _, err := source.Fetch(filename) c.Assert(err, gc.IsNil) defer rc.Close() retrieved, err := ioutil.ReadAll(rc) c.Assert(err, gc.IsNil) c.Assert(retrieved, gc.DeepEquals, content) }
// appendMatchingTools updates matchingTools with tools metadata records from tools which belong to the // specified series. If a tools record already exists in matchingTools, it is not overwritten. func appendMatchingTools(source simplestreams.DataSource, matchingTools []interface{}, tools map[string]interface{}, cons simplestreams.LookupConstraint) []interface{} { toolsMap := make(map[version.Binary]*ToolsMetadata, len(matchingTools)) for _, val := range matchingTools { tm := val.(*ToolsMetadata) toolsMap[tm.binary()] = tm } for _, val := range tools { tm := val.(*ToolsMetadata) if !set.NewStrings(cons.Params().Series...).Contains(tm.Release) { continue } if toolsConstraint, ok := cons.(*ToolsConstraint); ok { tmNumber := version.MustParse(tm.Version) if toolsConstraint.Version == version.Zero { if toolsConstraint.Released && tmNumber.IsDev() { continue } if toolsConstraint.MajorVersion >= 0 && toolsConstraint.MajorVersion != tmNumber.Major { continue } if toolsConstraint.MinorVersion >= 0 && toolsConstraint.MinorVersion != tmNumber.Minor { continue } } else { if toolsConstraint.Version != tmNumber { continue } } } if _, ok := toolsMap[tm.binary()]; !ok { tm.FullPath, _ = source.URL(tm.Path) matchingTools = append(matchingTools, tm) } } return matchingTools }