-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds test for reproducibility of the builds
- Loading branch information
1 parent
daccbc7
commit 7fa9378
Showing
2 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package integration_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/paketo-buildpacks/occam" | ||
"github.com/sclevine/spec" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func testReproducibleBuilds(t *testing.T, context spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
|
||
pack occam.Pack | ||
docker occam.Docker | ||
) | ||
|
||
it.Before(func() { | ||
pack = occam.NewPack() | ||
docker = occam.NewDocker() | ||
}) | ||
|
||
context("when building a node app that does not use a package manager", func() { | ||
var ( | ||
image occam.Image | ||
|
||
name string | ||
source string | ||
) | ||
|
||
it.Before(func() { | ||
var err error | ||
name, err = occam.RandomName() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
source, err = occam.Source(filepath.Join("testdata", "no_package_manager")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
Expect(os.RemoveAll(source)).To(Succeed()) | ||
}) | ||
|
||
it("creates a two identical images from the same input", func() { | ||
var err error | ||
var logs fmt.Stringer | ||
image, logs, err = pack.WithNoColor().Build. | ||
WithBuildpacks(nodeBuildpack). | ||
WithPullPolicy("never"). | ||
Execute(name, source) | ||
Expect(err).NotTo(HaveOccurred(), logs.String()) | ||
|
||
firstID := image.ID | ||
|
||
// Delete the first image | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
|
||
image, logs, err = pack.WithNoColor().Build. | ||
WithBuildpacks(nodeBuildpack). | ||
WithPullPolicy("never"). | ||
WithClearCache(). | ||
Execute(name, source) | ||
Expect(err).NotTo(HaveOccurred(), logs.String()) | ||
|
||
Expect(firstID).To(Equal(image.ID)) | ||
}) | ||
}) | ||
|
||
context("when building a node app that uses npm", func() { | ||
var ( | ||
image occam.Image | ||
|
||
name string | ||
source string | ||
) | ||
|
||
it.Before(func() { | ||
var err error | ||
name, err = occam.RandomName() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
source, err = occam.Source(filepath.Join("testdata", "npm")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
Expect(os.RemoveAll(source)).To(Succeed()) | ||
}) | ||
|
||
it("creates a two identical images from the same input", func() { | ||
var err error | ||
var logs fmt.Stringer | ||
image, logs, err = pack.WithNoColor().Build. | ||
WithBuildpacks(nodeBuildpack). | ||
WithPullPolicy("never"). | ||
Execute(name, source) | ||
Expect(err).NotTo(HaveOccurred(), logs.String()) | ||
|
||
firstID := image.ID | ||
|
||
// Delete the first image | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
|
||
image, logs, err = pack.WithNoColor().Build. | ||
WithBuildpacks(nodeBuildpack). | ||
WithPullPolicy("never"). | ||
WithClearCache(). | ||
Execute(name, source) | ||
Expect(err).NotTo(HaveOccurred(), logs.String()) | ||
|
||
Expect(firstID).To(Equal(image.ID)) | ||
}) | ||
}) | ||
|
||
context("when building a node app that uses yarn", func() { | ||
var ( | ||
image occam.Image | ||
|
||
name string | ||
source string | ||
) | ||
|
||
it.Before(func() { | ||
var err error | ||
name, err = occam.RandomName() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
source, err = occam.Source(filepath.Join("testdata", "yarn")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
Expect(os.RemoveAll(source)).To(Succeed()) | ||
}) | ||
|
||
it("creates a two identical images from the same input", func() { | ||
var err error | ||
var logs fmt.Stringer | ||
image, logs, err = pack.WithNoColor().Build. | ||
WithBuildpacks(nodeBuildpack). | ||
WithPullPolicy("never"). | ||
Execute(name, source) | ||
Expect(err).NotTo(HaveOccurred(), logs.String()) | ||
|
||
firstID := image.ID | ||
|
||
// Delete the first image | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
|
||
image, logs, err = pack.WithNoColor().Build. | ||
WithBuildpacks(nodeBuildpack). | ||
WithPullPolicy("never"). | ||
WithClearCache(). | ||
Execute(name, source) | ||
Expect(err).NotTo(HaveOccurred(), logs.String()) | ||
|
||
Expect(firstID).To(Equal(image.ID)) | ||
}) | ||
}) | ||
} |