Skip to content

Commit

Permalink
Adds test for reproducibility of the builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt authored and paketo-bot committed Aug 16, 2022
1 parent daccbc7 commit 7fa9378
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 1 deletion.
3 changes: 2 additions & 1 deletion integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestIntegration(t *testing.T) {

suite := spec.New("Integration", spec.Parallel(), spec.Report(report.Terminal{}))
suite("NPM", testNPM)
suite("Yarn", testYarn)
suite("NodeStart", testNodeStart)
suite("ReproducibleBuilds", testReproducibleBuilds)
suite("Yarn", testYarn)
suite.Run(t)
}
174 changes: 174 additions & 0 deletions integration/reproducible_builds_test.go
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))
})
})
}

0 comments on commit 7fa9378

Please sign in to comment.