Skip to content

Commit

Permalink
Fix file leak
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Romero <root@jromero.codes>
  • Loading branch information
jromero committed Mar 17, 2020
1 parent e7d4f0b commit e743f8b
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions internal/buildpackage/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"

"github.com/buildpacks/imgutil/fakes"
Expand Down Expand Up @@ -513,12 +514,11 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {

subject.SetBuildpack(buildpack1)

tempFile, err := ioutil.TempFile(tmpDir, "package-*.cnb")
h.AssertNil(t, err)
h.AssertNil(t, subject.SaveAsFile(tempFile.Name()))
outputFile := filepath.Join(tmpDir, fmt.Sprintf("package-%s.cnb", h.RandString(10)))
h.AssertNil(t, subject.SaveAsFile(outputFile))

// config: application/vnd.docker.container.image.v1+json
h.AssertOnTarEntry(t, tempFile.Name(),
h.AssertOnTarEntry(t, outputFile,
"/blobs/sha256/12664caac120282c7b806ab1c269b11f050a3f635e844c18ea83240a82628eb4",
h.HasOwnerAndGroup(0, 0),
h.IsJSON(),
Expand All @@ -535,12 +535,11 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
subject.SetBuildpack(buildpack1)

tempFile, err := ioutil.TempFile(tmpDir, "package-*.cnb")
h.AssertNil(t, err)
h.AssertNil(t, subject.SaveAsFile(tempFile.Name()))
outputFile := filepath.Join(tmpDir, fmt.Sprintf("package-%s.cnb", h.RandString(10)))
h.AssertNil(t, subject.SaveAsFile(outputFile))

// config: application/vnd.docker.container.image.v1+json
h.AssertOnTarEntry(t, tempFile.Name(),
h.AssertOnTarEntry(t, outputFile,
"/blobs/sha256/12664caac120282c7b806ab1c269b11f050a3f635e844c18ea83240a82628eb4",
h.HasOwnerAndGroup(0, 0),
h.IsJSON(),
Expand All @@ -557,33 +556,32 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
subject.SetBuildpack(buildpack1)

tempFile, err := ioutil.TempFile(tmpDir, "package-*.cnb")
h.AssertNil(t, err)
h.AssertNil(t, subject.SaveAsFile(tempFile.Name()))
outputFile := filepath.Join(tmpDir, fmt.Sprintf("package-%s.cnb", h.RandString(10)))
h.AssertNil(t, subject.SaveAsFile(outputFile))

h.AssertOnTarEntry(t, tempFile.Name(), "/index.json",
h.AssertOnTarEntry(t, outputFile, "/index.json",
h.HasOwnerAndGroup(0, 0))
h.AssertOnTarEntry(t, tempFile.Name(), "/blobs",
h.AssertOnTarEntry(t, outputFile, "/blobs",
h.IsDirectory(),
h.HasOwnerAndGroup(0, 0))
h.AssertOnTarEntry(t, tempFile.Name(), "/blobs/sha256",
h.AssertOnTarEntry(t, outputFile, "/blobs/sha256",
h.IsDirectory(),
h.HasOwnerAndGroup(0, 0))
// manifest: application/vnd.docker.distribution.manifest.v2+json
h.AssertOnTarEntry(t, tempFile.Name(),
h.AssertOnTarEntry(t, outputFile,
"/blobs/sha256/97910ef639813d29fdf6dab99d11f6d06ffdf735297fffe997dad3f89116f327",
h.HasOwnerAndGroup(0, 0),
h.IsJSON())
// config: application/vnd.docker.container.image.v1+json
h.AssertOnTarEntry(t, tempFile.Name(),
h.AssertOnTarEntry(t, outputFile,
"/blobs/sha256/12664caac120282c7b806ab1c269b11f050a3f635e844c18ea83240a82628eb4",
h.HasOwnerAndGroup(0, 0),
h.IsJSON())

// layer: application/vnd.docker.image.rootfs.diff.tar.gzip
buildpackLayerSHA, err := computeBuildpackLayerSHA(buildpack1)
h.AssertNil(t, err)
h.AssertOnTarEntry(t, tempFile.Name(),
h.AssertOnTarEntry(t, outputFile,
"/blobs/sha256/"+buildpackLayerSHA,
h.HasOwnerAndGroup(0, 0),
h.IsGzipped(),
Expand Down

0 comments on commit e743f8b

Please sign in to comment.