From a57bf55fb38d54696af96073fbbb8424e115d5ff Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 4 Jun 2024 18:49:51 +0000 Subject: [PATCH] Updates fetchers to create buildpackages --- fakes/buildpack_cache.go | 18 ++++---- fakes/executable.go | 6 +-- fakes/git_release_fetcher.go | 18 ++++---- fakes/namer.go | 6 +-- fakes/packager.go | 6 +-- file_system.go | 15 ------- file_system_test.go | 29 ------------- init_test.go | 1 - local_fetcher.go | 2 +- local_fetcher_test.go | 4 +- packing_tools.go | 47 +++++++++++++++++++-- packing_tools_test.go | 80 ++++++++++++++++++++++++++---------- remote_fetcher.go | 15 ++++--- remote_fetcher_test.go | 44 ++++++++++---------- 14 files changed, 164 insertions(+), 127 deletions(-) delete mode 100644 file_system.go delete mode 100644 file_system_test.go diff --git a/fakes/buildpack_cache.go b/fakes/buildpack_cache.go index c3cea3e..e88efbe 100644 --- a/fakes/buildpack_cache.go +++ b/fakes/buildpack_cache.go @@ -8,7 +8,7 @@ import ( type BuildpackCache struct { DirCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Returns struct { String string @@ -16,7 +16,7 @@ type BuildpackCache struct { Stub func() string } GetCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Key string @@ -29,7 +29,7 @@ type BuildpackCache struct { Stub func(string) (freezer.CacheEntry, bool, error) } SetCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Key string @@ -43,8 +43,8 @@ type BuildpackCache struct { } func (f *BuildpackCache) Dir() string { - f.DirCall.Lock() - defer f.DirCall.Unlock() + f.DirCall.mutex.Lock() + defer f.DirCall.mutex.Unlock() f.DirCall.CallCount++ if f.DirCall.Stub != nil { return f.DirCall.Stub() @@ -52,8 +52,8 @@ func (f *BuildpackCache) Dir() string { return f.DirCall.Returns.String } func (f *BuildpackCache) Get(param1 string) (freezer.CacheEntry, bool, error) { - f.GetCall.Lock() - defer f.GetCall.Unlock() + f.GetCall.mutex.Lock() + defer f.GetCall.mutex.Unlock() f.GetCall.CallCount++ f.GetCall.Receives.Key = param1 if f.GetCall.Stub != nil { @@ -62,8 +62,8 @@ func (f *BuildpackCache) Get(param1 string) (freezer.CacheEntry, bool, error) { return f.GetCall.Returns.CacheEntry, f.GetCall.Returns.Bool, f.GetCall.Returns.Error } func (f *BuildpackCache) Set(param1 string, param2 freezer.CacheEntry) error { - f.SetCall.Lock() - defer f.SetCall.Unlock() + f.SetCall.mutex.Lock() + defer f.SetCall.mutex.Unlock() f.SetCall.CallCount++ f.SetCall.Receives.Key = param1 f.SetCall.Receives.CachedEntry = param2 diff --git a/fakes/executable.go b/fakes/executable.go index bc53188..5603000 100644 --- a/fakes/executable.go +++ b/fakes/executable.go @@ -8,7 +8,7 @@ import ( type Executable struct { ExecuteCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Execution pexec.Execution @@ -21,8 +21,8 @@ type Executable struct { } func (f *Executable) Execute(param1 pexec.Execution) error { - f.ExecuteCall.Lock() - defer f.ExecuteCall.Unlock() + f.ExecuteCall.mutex.Lock() + defer f.ExecuteCall.mutex.Unlock() f.ExecuteCall.CallCount++ f.ExecuteCall.Receives.Execution = param1 if f.ExecuteCall.Stub != nil { diff --git a/fakes/git_release_fetcher.go b/fakes/git_release_fetcher.go index d488d97..d7ac5f2 100644 --- a/fakes/git_release_fetcher.go +++ b/fakes/git_release_fetcher.go @@ -9,7 +9,7 @@ import ( type GitReleaseFetcher struct { GetCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Org string @@ -22,7 +22,7 @@ type GitReleaseFetcher struct { Stub func(string, string) (github.Release, error) } GetReleaseAssetCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Asset github.ReleaseAsset @@ -34,7 +34,7 @@ type GitReleaseFetcher struct { Stub func(github.ReleaseAsset) (io.ReadCloser, error) } GetReleaseTarballCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Url string @@ -48,8 +48,8 @@ type GitReleaseFetcher struct { } func (f *GitReleaseFetcher) Get(param1 string, param2 string) (github.Release, error) { - f.GetCall.Lock() - defer f.GetCall.Unlock() + f.GetCall.mutex.Lock() + defer f.GetCall.mutex.Unlock() f.GetCall.CallCount++ f.GetCall.Receives.Org = param1 f.GetCall.Receives.Repo = param2 @@ -59,8 +59,8 @@ func (f *GitReleaseFetcher) Get(param1 string, param2 string) (github.Release, e return f.GetCall.Returns.Release, f.GetCall.Returns.Error } func (f *GitReleaseFetcher) GetReleaseAsset(param1 github.ReleaseAsset) (io.ReadCloser, error) { - f.GetReleaseAssetCall.Lock() - defer f.GetReleaseAssetCall.Unlock() + f.GetReleaseAssetCall.mutex.Lock() + defer f.GetReleaseAssetCall.mutex.Unlock() f.GetReleaseAssetCall.CallCount++ f.GetReleaseAssetCall.Receives.Asset = param1 if f.GetReleaseAssetCall.Stub != nil { @@ -69,8 +69,8 @@ func (f *GitReleaseFetcher) GetReleaseAsset(param1 github.ReleaseAsset) (io.Read return f.GetReleaseAssetCall.Returns.ReadCloser, f.GetReleaseAssetCall.Returns.Error } func (f *GitReleaseFetcher) GetReleaseTarball(param1 string) (io.ReadCloser, error) { - f.GetReleaseTarballCall.Lock() - defer f.GetReleaseTarballCall.Unlock() + f.GetReleaseTarballCall.mutex.Lock() + defer f.GetReleaseTarballCall.mutex.Unlock() f.GetReleaseTarballCall.CallCount++ f.GetReleaseTarballCall.Receives.Url = param1 if f.GetReleaseTarballCall.Stub != nil { diff --git a/fakes/namer.go b/fakes/namer.go index 6f3929c..2387413 100644 --- a/fakes/namer.go +++ b/fakes/namer.go @@ -4,7 +4,7 @@ import "sync" type Namer struct { RandomNameCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { Name string @@ -18,8 +18,8 @@ type Namer struct { } func (f *Namer) RandomName(param1 string) (string, error) { - f.RandomNameCall.Lock() - defer f.RandomNameCall.Unlock() + f.RandomNameCall.mutex.Lock() + defer f.RandomNameCall.mutex.Unlock() f.RandomNameCall.CallCount++ f.RandomNameCall.Receives.Name = param1 if f.RandomNameCall.Stub != nil { diff --git a/fakes/packager.go b/fakes/packager.go index 7646932..52cdde7 100644 --- a/fakes/packager.go +++ b/fakes/packager.go @@ -4,7 +4,7 @@ import "sync" type Packager struct { ExecuteCall struct { - sync.Mutex + mutex sync.Mutex CallCount int Receives struct { BuildpackDir string @@ -20,8 +20,8 @@ type Packager struct { } func (f *Packager) Execute(param1 string, param2 string, param3 string, param4 bool) error { - f.ExecuteCall.Lock() - defer f.ExecuteCall.Unlock() + f.ExecuteCall.mutex.Lock() + defer f.ExecuteCall.mutex.Unlock() f.ExecuteCall.CallCount++ f.ExecuteCall.Receives.BuildpackDir = param1 f.ExecuteCall.Receives.Output = param2 diff --git a/file_system.go b/file_system.go deleted file mode 100644 index 8aa38d5..0000000 --- a/file_system.go +++ /dev/null @@ -1,15 +0,0 @@ -package freezer - -type FileSystem struct { - tempDir func(string, string) (string, error) -} - -func NewFileSystem(tempDir func(string, string) (string, error)) FileSystem { - return FileSystem{ - tempDir: tempDir, - } -} - -func (fs FileSystem) TempDir(tempDir, tempName string) (string, error) { - return fs.tempDir(tempDir, tempName) -} diff --git a/file_system_test.go b/file_system_test.go deleted file mode 100644 index cb2c5db..0000000 --- a/file_system_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package freezer_test - -import ( - "os" - "testing" - - "github.com/ForestEckhardt/freezer" - . "github.com/onsi/gomega" - "github.com/sclevine/spec" -) - -func testFileSystem(t *testing.T, context spec.G, it spec.S) { - var Expect = NewWithT(t).Expect - - context("TempDir", func() { - it("returns the value given from the TempDir function", func() { - filename, err := os.MkdirTemp("", "tempDir") - defer os.RemoveAll(filename) - - fileSystem := freezer.NewFileSystem(func(string, string) (string, error) { - return filename, err - }) - - tName, tErr := fileSystem.TempDir("", "tempDir") - Expect(tName).To(Equal(filename)) - Expect(tErr).To(BeNil()) - }) - }) -} diff --git a/init_test.go b/init_test.go index 7cbbc99..b6b4b5f 100644 --- a/init_test.go +++ b/init_test.go @@ -12,7 +12,6 @@ var gitToken string func TestFreezer(t *testing.T) { suite := spec.New("freezer", spec.Report(report.Terminal{})) suite("CacheManager", testCacheManager) - suite("FileSystem", testFileSystem) suite("LocalFetcher", testLocalFetcher) suite("PackingTools", testPackingTools) suite("RandomName", testRandomName) diff --git a/local_fetcher.go b/local_fetcher.go index 96d717e..f387578 100644 --- a/local_fetcher.go +++ b/local_fetcher.go @@ -46,7 +46,7 @@ func (l LocalFetcher) Get(buildpack LocalBuildpack) (string, error) { return "", fmt.Errorf("random name generation failed: %w", err) } - path := filepath.Join(buildpackCacheDir, fmt.Sprintf("%s.tgz", name)) + path := filepath.Join(buildpackCacheDir, fmt.Sprintf("%s.cnb", name)) cachedEntry, exist, err := l.buildpackCache.Get(key) if err != nil { diff --git a/local_fetcher_test.go b/local_fetcher_test.go index 7048bea..bb4ab86 100644 --- a/local_fetcher_test.go +++ b/local_fetcher_test.go @@ -70,13 +70,13 @@ func testLocalFetcher(t *testing.T, context spec.G, it spec.S) { Expect(namer.RandomNameCall.Receives.Name).To(Equal("some-buildpack")) Expect(packager.ExecuteCall.Receives.BuildpackDir).To(Equal("path/to/buildpack")) - Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-buildpack", "some-buildpack-random-string.tgz"))) + Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-buildpack", "some-buildpack-random-string.cnb"))) Expect(packager.ExecuteCall.Receives.Version).To(Equal("some-version")) Expect(packager.ExecuteCall.Receives.Cached).To(BeFalse()) Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-buildpack", "some-buildpack-random-string.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-buildpack", "some-buildpack-random-string.cnb"))) }) }) diff --git a/packing_tools.go b/packing_tools.go index a9a88ee..9494bc9 100644 --- a/packing_tools.go +++ b/packing_tools.go @@ -1,8 +1,10 @@ package freezer import ( + "fmt" "os" "path/filepath" + "runtime" "github.com/paketo-buildpacks/packit/v2/pexec" ) @@ -13,12 +15,16 @@ type Executable interface { } type PackingTools struct { - jam Executable + jam Executable + pack Executable + tempOutput func(dir string, pattern string) (string, error) } func NewPackingTools() PackingTools { return PackingTools{ - jam: pexec.NewExecutable("jam"), + jam: pexec.NewExecutable("jam"), + pack: pexec.NewExecutable("pack"), + tempOutput: os.MkdirTemp, } } @@ -27,11 +33,27 @@ func (p PackingTools) WithExecutable(executable Executable) PackingTools { return p } +func (p PackingTools) WithPack(pack Executable) PackingTools { + p.pack = pack + return p +} + +func (p PackingTools) WithTempOutput(tempOutput func(string, string) (string, error)) PackingTools { + p.tempOutput = tempOutput + return p +} + func (p PackingTools) Execute(buildpackDir, output, version string, cached bool) error { + jamOutput, err := p.tempOutput("", "") + if err != nil { + return err + } + defer os.RemoveAll(jamOutput) + args := []string{ "pack", "--buildpack", filepath.Join(buildpackDir, "buildpack.toml"), - "--output", output, + "--output", filepath.Join(jamOutput, fmt.Sprintf("%s.tgz", version)), "--version", version, } @@ -39,7 +61,24 @@ func (p PackingTools) Execute(buildpackDir, output, version string, cached bool) args = append(args, "--offline") } - return p.jam.Execute(pexec.Execution{ + err = p.jam.Execute(pexec.Execution{ + Args: args, + Stdout: os.Stdout, + Stderr: os.Stderr, + }) + if err != nil { + return err + } + + args = []string{ + "buildpack", "package", + output, + "--path", filepath.Join(jamOutput, fmt.Sprintf("%s.tgz", version)), + "--format", "file", + "--target", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + } + + return p.pack.Execute(pexec.Execution{ Args: args, Stdout: os.Stdout, Stderr: os.Stderr, diff --git a/packing_tools_test.go b/packing_tools_test.go index cf00439..9a27034 100644 --- a/packing_tools_test.go +++ b/packing_tools_test.go @@ -2,8 +2,9 @@ package freezer_test import ( "errors" - "os" + "fmt" "path/filepath" + "runtime" "testing" "github.com/ForestEckhardt/freezer" @@ -17,63 +18,100 @@ func testPackingTools(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect - buildpackDir string - executable *fakes.Executable + pack *fakes.Executable + tempOutput func(string, string) (string, error) packingTools freezer.PackingTools ) it.Before(func() { - var err error - buildpackDir, err = os.MkdirTemp("", "buildpack-dir") - Expect(err).ToNot(HaveOccurred()) - executable = &fakes.Executable{} + pack = &fakes.Executable{} - packingTools = freezer.NewPackingTools().WithExecutable(executable) + tempOutput = func(string, string) (string, error) { + return "some-jam-output", nil + } - }) + packingTools = freezer.NewPackingTools().WithExecutable(executable).WithPack(pack).WithTempOutput(tempOutput) - it.After(func() { - Expect(os.RemoveAll(buildpackDir)).To(Succeed()) }) context("Execute", func() { it("creates a correct pexec.Execution", func() { - err := packingTools.Execute(buildpackDir, "some-output", "some-version", false) + err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", false) Expect(err).NotTo(HaveOccurred()) Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{ "pack", - "--buildpack", filepath.Join(buildpackDir, "buildpack.toml"), - "--output", "some-output", + "--buildpack", filepath.Join("some-buildpack-dir", "buildpack.toml"), + "--output", filepath.Join("some-jam-output", "some-version.tgz"), "--version", "some-version", })) + + Expect(pack.ExecuteCall.Receives.Execution.Args).To(Equal([]string{ + "buildpack", "package", + "some-output", + "--path", filepath.Join("some-jam-output", "some-version.tgz"), + "--format", "file", + "--target", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + })) }) context("when cache is set to true", func() { it("creates a correct pexec.Execution", func() { - err := packingTools.Execute(buildpackDir, "some-output", "some-version", true) + err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true) Expect(err).NotTo(HaveOccurred()) Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{ "pack", - "--buildpack", filepath.Join(buildpackDir, "buildpack.toml"), - "--output", "some-output", + "--buildpack", filepath.Join("some-buildpack-dir", "buildpack.toml"), + "--output", filepath.Join("some-jam-output", "some-version.tgz"), "--version", "some-version", "--offline", })) + + Expect(pack.ExecuteCall.Receives.Execution.Args).To(Equal([]string{ + "buildpack", "package", + "some-output", + "--path", filepath.Join("some-jam-output", "some-version.tgz"), + "--format", "file", + "--target", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + })) }) }) context("failure cases", func() { - context("when the execution returns an error", func() { + context("when the tempDir creation fails returns an error", func() { + it.Before(func() { + tempOutput = func(string, string) (string, error) { + return "", errors.New("some tempDir error") + } + + packingTools = packingTools.WithTempOutput(tempOutput) + }) + it("returns an error", func() { + err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true) + Expect(err).To(MatchError("some tempDir error")) + }) + }) + + context("when the jam execution returns an error", func() { + it.Before(func() { + executable.ExecuteCall.Returns.Error = errors.New("some jam error") + }) + it("returns an error", func() { + err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true) + Expect(err).To(MatchError("some jam error")) + }) + }) + + context("when the pack execution returns an error", func() { it.Before(func() { - executable.ExecuteCall.Returns.Error = errors.New("some error") + pack.ExecuteCall.Returns.Error = errors.New("some pack error") }) it("returns an error", func() { - err := packingTools.Execute(buildpackDir, "some-output", "some-version", true) - Expect(err).To(MatchError("some error")) + err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true) + Expect(err).To(MatchError("some pack error")) }) }) }) diff --git a/remote_fetcher.go b/remote_fetcher.go index 75c9f7e..7346109 100644 --- a/remote_fetcher.go +++ b/remote_fetcher.go @@ -34,15 +34,15 @@ type RemoteFetcher struct { buildpackCache BuildpackCache gitReleaseFetcher GitReleaseFetcher packager Packager - fileSystem FileSystem + fileSystem func(dir string, pattern string) (string, error) } -func NewRemoteFetcher(buildpackCache BuildpackCache, gitReleaseFetcher GitReleaseFetcher, packager Packager, fileSystem FileSystem) RemoteFetcher { +func NewRemoteFetcher(buildpackCache BuildpackCache, gitReleaseFetcher GitReleaseFetcher, packager Packager) RemoteFetcher { return RemoteFetcher{ buildpackCache: buildpackCache, gitReleaseFetcher: gitReleaseFetcher, packager: packager, - fileSystem: fileSystem, + fileSystem: os.MkdirTemp, } } @@ -51,6 +51,11 @@ func (r RemoteFetcher) WithPackager(packager Packager) RemoteFetcher { return r } +func (r RemoteFetcher) WithFileSystem(fileSystem func(string, string) (string, error)) RemoteFetcher { + r.fileSystem = fileSystem + return r +} + func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) { release, err := r.gitReleaseFetcher.Get(buildpack.Org, buildpack.Repo) if err != nil { @@ -97,10 +102,10 @@ func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) { } } - path = filepath.Join(buildpackCacheDir, fmt.Sprintf("%s.tgz", tagName)) + path = filepath.Join(buildpackCacheDir, fmt.Sprintf("%s.cnb", tagName)) if missingReleaseArtifacts || buildpack.Offline { - downloadDir, err := r.fileSystem.TempDir("", buildpack.Repo) + downloadDir, err := r.fileSystem("", buildpack.Repo) if err != nil { return "", err } diff --git a/remote_fetcher_test.go b/remote_fetcher_test.go index 4e65c07..89b1f77 100644 --- a/remote_fetcher_test.go +++ b/remote_fetcher_test.go @@ -31,7 +31,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { buildpackCache *fakes.BuildpackCache remoteBuildpack freezer.RemoteBuildpack packager *fakes.Packager - fileSystem freezer.FileSystem + fileSystem func(string, string) (string, error) remoteFetcher freezer.RemoteFetcher ) @@ -83,11 +83,11 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { downloadDir, err = os.MkdirTemp(tmpDir, "downloadDir") Expect(err).NotTo(HaveOccurred()) - fileSystem = freezer.NewFileSystem(func(string, string) (string, error) { + fileSystem = func(string, string) (string, error) { return downloadDir, nil - }) + } - remoteFetcher = freezer.NewRemoteFetcher(buildpackCache, gitReleaseFetcher, packager, fileSystem) + remoteFetcher = freezer.NewRemoteFetcher(buildpackCache, gitReleaseFetcher, packager).WithFileSystem(fileSystem) }) @@ -144,8 +144,8 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { URL: "some-url", })) - Expect(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz")).To(BeAnExistingFile()) - file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz")) + Expect(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb")).To(BeAnExistingFile()) + file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb")) Expect(err).ToNot(HaveOccurred()) err = vacation.NewArchive(file).Decompress(filepath.Join(cacheDir, "some-org", "some-repo")) @@ -157,7 +157,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb"))) }) }) @@ -175,13 +175,13 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(gitReleaseFetcher.GetReleaseTarballCall.Receives.Url).To(Equal("some-tarball-url")) Expect(packager.ExecuteCall.Receives.BuildpackDir).To(Equal(downloadDir)) - Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.tgz"))) + Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.cnb"))) Expect(packager.ExecuteCall.Receives.Version).To(Equal("some-tag")) Expect(packager.ExecuteCall.Receives.Cached).To(BeTrue()) Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.cnb"))) }) }) }) @@ -245,7 +245,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(gitReleaseFetcher.GetReleaseTarballCall.Receives.Url).To(Equal("some-tarball-url")) Expect(packager.ExecuteCall.Receives.BuildpackDir).To(Equal(downloadDir)) - Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz"))) + Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb"))) Expect(packager.ExecuteCall.Receives.Version).To(Equal("some-tag")) Expect(packager.ExecuteCall.Receives.Cached).To(BeFalse()) @@ -253,7 +253,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb"))) }) }) @@ -271,7 +271,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(gitReleaseFetcher.GetReleaseTarballCall.Receives.Url).To(Equal("some-tarball-url")) Expect(packager.ExecuteCall.Receives.BuildpackDir).To(Equal(downloadDir)) - Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.tgz"))) + Expect(packager.ExecuteCall.Receives.Output).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.cnb"))) Expect(packager.ExecuteCall.Receives.Version).To(Equal("some-tag")) Expect(packager.ExecuteCall.Receives.Cached).To(BeTrue()) @@ -279,7 +279,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "cached", "some-tag.cnb"))) }) }) }) @@ -303,8 +303,8 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { URL: "some-url", })) - Expect(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz")).To(BeAnExistingFile()) - file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz")) + Expect(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb")).To(BeAnExistingFile()) + file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb")) Expect(err).ToNot(HaveOccurred()) err = vacation.NewArchive(file).Decompress(filepath.Join(cacheDir, "some-org", "some-repo")) @@ -316,7 +316,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "some-tag.cnb"))) }) }) @@ -352,8 +352,8 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { URL: "some-url", })) - Expect(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz")).To(BeAnExistingFile()) - file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz")) + Expect(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.cnb")).To(BeAnExistingFile()) + file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.cnb")) Expect(err).ToNot(HaveOccurred()) err = vacation.NewArchive(file).Decompress(filepath.Join(cacheDir, "some-org", "some-repo")) @@ -365,7 +365,7 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Expect(buildpackCache.SetCall.CallCount).To(Equal(1)) - Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz"))) + Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.cnb"))) }) }) @@ -426,11 +426,11 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) { Version: "some-other-tag", } - fileSystem = freezer.NewFileSystem(func(string, string) (string, error) { + fileSystem = func(string, string) (string, error) { return "", errors.New("failed to create temp directory") - }) + } - remoteFetcher = freezer.NewRemoteFetcher(buildpackCache, gitReleaseFetcher, packager, fileSystem) + remoteFetcher = freezer.NewRemoteFetcher(buildpackCache, gitReleaseFetcher, packager).WithFileSystem(fileSystem) }) it("returns an error", func() {