// GetMockBuildTools returns a sync.BuildToolsTarballFunc implementation which generates // a fake tools tarball. func GetMockBuildTools(c *gc.C) sync.BuildToolsTarballFunc { return func(forceVersion *version.Number, stream string) (*sync.BuiltTools, error) { vers := version.Binary{ Number: version.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } if forceVersion != nil { vers.Number = *forceVersion } tgz, checksum := coretesting.TarGz( coretesting.NewTarFile(names.Jujud, 0777, "jujud contents "+vers.String())) toolsDir, err := ioutil.TempDir("", "juju-tools-"+stream) c.Assert(err, jc.ErrorIsNil) name := "name" ioutil.WriteFile(filepath.Join(toolsDir, name), tgz, 0777) return &sync.BuiltTools{ Dir: toolsDir, StorageName: name, Version: vers, Size: int64(len(tgz)), Sha256Hash: checksum, }, nil } }
func makeToolsList(series string) tools.List { var toolsVersion version.Binary toolsVersion.Number = version.MustParse("1.26.0") toolsVersion.Arch = arch.AMD64 toolsVersion.Series = series return tools.List{{ Version: toolsVersion, URL: fmt.Sprintf("http://example.com/tools/juju-%s.tgz", toolsVersion), SHA256: "1234567890abcdef", Size: 1024, }} }
func GetMockBundleTools(c *gc.C) tools.BundleToolsFunc { return func(w io.Writer, forceVersion *version.Number) (version.Binary, string, error) { vers := version.Binary{ Number: version.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } if forceVersion != nil { vers.Number = *forceVersion } sha256Hash := fmt.Sprintf("%x", sha256.New().Sum(nil)) return vers, sha256Hash, nil } }