Skip to content

Commit

Permalink
update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Wigmore authored and sophiewigmore committed Jan 25, 2023
1 parent 89cba82 commit af0f70e
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 135 deletions.
263 changes: 129 additions & 134 deletions integration/reuse_layer_rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,141 +170,136 @@ func testReusingLayerRebuild(t *testing.T, context spec.G, it spec.S) {
})
})

// This test is not currently applicable on jammy because currently Jammy support
// only applies to one version of Ruby (version 3.1 and above)
// This condition can be removed when multiple versions of Ruby are supported on Jammy (e.g. 3.0 or 3.2)
if builder.LocalInfo.Stack.ID != "io.buildpacks.stacks.jammy" {
context("when an app is rebuilt and there is a change", func() {
it("rebuilds the layer", func() {
var (
err error
logs fmt.Stringer
firstImage occam.Image
secondImage occam.Image

firstContainer occam.Container
secondContainer occam.Container
context("when an app is rebuilt and there is a change", func() {
it("rebuilds the layer", func() {
var (
err error
logs fmt.Stringer
firstImage occam.Image
secondImage occam.Image

firstContainer occam.Container
secondContainer occam.Container
)

source, err = occam.Source(filepath.Join("testdata", "simple_app"))
Expect(err).NotTo(HaveOccurred())

build := pack.Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.MRI.Online,
settings.Buildpacks.BuildPlan.Online,
)

source, err = occam.Source(filepath.Join("testdata", "simple_app"))
Expect(err).NotTo(HaveOccurred())

build := pack.Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.MRI.Online,
settings.Buildpacks.BuildPlan.Online,
)

firstImage, logs, err = build.
WithEnv(map[string]string{"BP_MRI_VERSION": "3.0.x"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String)

imageIDs[firstImage.ID] = struct{}{}

Expect(firstImage.Buildpacks).To(HaveLen(2))
Expect(firstImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID))
Expect(firstImage.Buildpacks[0].Layers).To(HaveKey("mri"))

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Resolving MRI version",
" Candidate version sources (in priority order):",
" BP_MRI_VERSION -> \"3.0.x\"",
" <unknown> -> \"\"",
))

Expect(logs).To(ContainLines(
MatchRegexp(` Selected MRI version \(using BP_MRI_VERSION\): 3\.0\.\d+`),
))

Expect(logs).To(ContainLines(
" Executing build process",
MatchRegexp(` Installing MRI 3\.0\.\d+`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
))

Expect(logs).To(ContainLines(
" Configuring build environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.0\.\d+:/layers/%s/mri/lib/ruby/gems/3\.0\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

Expect(logs).To(ContainLines(
" Configuring launch environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.0\.\d+:/layers/%s/mri/lib/ruby/gems/3\.0\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

firstContainer, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
WithCommand("ruby run.rb").Execute(firstImage.ID)
Expect(err).NotTo(HaveOccurred())

containerIDs[firstContainer.ID] = struct{}{}

Eventually(firstContainer).Should(BeAvailable())

// Second pack build
secondImage, logs, err = build.
WithEnv(map[string]string{"BP_MRI_VERSION": "3.1.x"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())

imageIDs[secondImage.ID] = struct{}{}

Expect(secondImage.Buildpacks).To(HaveLen(2))
Expect(secondImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID))
Expect(secondImage.Buildpacks[0].Layers).To(HaveKey("mri"))

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Resolving MRI version",
" Candidate version sources (in priority order):",
" BP_MRI_VERSION -> \"3.1.x\"",
" <unknown> -> \"\"",
))

Expect(logs).To(ContainLines(
MatchRegexp(` Selected MRI version \(using BP_MRI_VERSION\): 3\.1\.\d+`),
))

Expect(logs).To(ContainLines(
" Executing build process",
MatchRegexp(` Installing MRI 3\.1\.\d+`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
))

Expect(logs).To(ContainLines(
" Configuring build environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.1\.\d+:/layers/%s/mri/lib/ruby/gems/3\.1\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

Expect(logs).To(ContainLines(
" Configuring launch environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.1\.\d+:/layers/%s/mri/lib/ruby/gems/3\.1\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

secondContainer, err = docker.Container.Run.
WithCommand("ruby run.rb").
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(secondImage.ID)
Expect(err).NotTo(HaveOccurred())

containerIDs[secondContainer.ID] = struct{}{}

Eventually(secondContainer).Should(BeAvailable())
Eventually(secondContainer).Should(Serve(MatchRegexp(`Hello from Ruby 3\.1\.\d+`)).OnPort(8080))

Expect(secondImage.Buildpacks[0].Layers["mri"].SHA).NotTo(Equal(firstImage.Buildpacks[0].Layers["mri"].SHA))
})
firstImage, logs, err = build.
WithEnv(map[string]string{"BP_MRI_VERSION": "3.1.x"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String)

imageIDs[firstImage.ID] = struct{}{}

Expect(firstImage.Buildpacks).To(HaveLen(2))
Expect(firstImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID))
Expect(firstImage.Buildpacks[0].Layers).To(HaveKey("mri"))

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Resolving MRI version",
" Candidate version sources (in priority order):",
" BP_MRI_VERSION -> \"3.1.x\"",
" <unknown> -> \"\"",
))

Expect(logs).To(ContainLines(
MatchRegexp(` Selected MRI version \(using BP_MRI_VERSION\): 3\.1\.\d+`),
))

Expect(logs).To(ContainLines(
" Executing build process",
MatchRegexp(` Installing MRI 3\.1\.\d+`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
))

Expect(logs).To(ContainLines(
" Configuring build environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.1\.\d+:/layers/%s/mri/lib/ruby/gems/3\.1\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

Expect(logs).To(ContainLines(
" Configuring launch environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.1\.\d+:/layers/%s/mri/lib/ruby/gems/3\.1\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

firstContainer, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
WithCommand("ruby run.rb").Execute(firstImage.ID)
Expect(err).NotTo(HaveOccurred())

containerIDs[firstContainer.ID] = struct{}{}

Eventually(firstContainer).Should(BeAvailable())

// Second pack build
secondImage, logs, err = build.
WithEnv(map[string]string{"BP_MRI_VERSION": "3.2.x"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())

imageIDs[secondImage.ID] = struct{}{}

Expect(secondImage.Buildpacks).To(HaveLen(2))
Expect(secondImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID))
Expect(secondImage.Buildpacks[0].Layers).To(HaveKey("mri"))

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Resolving MRI version",
" Candidate version sources (in priority order):",
" BP_MRI_VERSION -> \"3.2.x\"",
" <unknown> -> \"\"",
))

Expect(logs).To(ContainLines(
MatchRegexp(` Selected MRI version \(using BP_MRI_VERSION\): 3\.2\.\d+`),
))

Expect(logs).To(ContainLines(
" Executing build process",
MatchRegexp(` Installing MRI 3\.2\.\d+`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
))

Expect(logs).To(ContainLines(
" Configuring build environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.2\.\d+:/layers/%s/mri/lib/ruby/gems/3\.2\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

Expect(logs).To(ContainLines(
" Configuring launch environment",
MatchRegexp(fmt.Sprintf(` GEM_PATH -> "/home/cnb/.local/share/gem/ruby/3\.2\.\d+:/layers/%s/mri/lib/ruby/gems/3\.2\.\d+"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))),
` MALLOC_ARENA_MAX -> "2"`,
))

secondContainer, err = docker.Container.Run.
WithCommand("ruby run.rb").
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(secondImage.ID)
Expect(err).NotTo(HaveOccurred())

containerIDs[secondContainer.ID] = struct{}{}

Eventually(secondContainer).Should(BeAvailable())
Eventually(secondContainer).Should(Serve(MatchRegexp(`Hello from Ruby 3\.2\.\d+`)).OnPort(8080))

Expect(secondImage.Buildpacks[0].Layers["mri"].SHA).NotTo(Equal(firstImage.Buildpacks[0].Layers["mri"].SHA))
})
}
})
}
1 change: 0 additions & 1 deletion integration/simple_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func testSimpleApp(t *testing.T, context spec.G, it spec.S) {

// This test is not currently applicable on jammy because currently Jammy support
// only applies to one version of Ruby (version 3.1 and above)
// This condition can be removed when multiple versions of Ruby are supported on Jammy (e.g. 3.0 or 3.2)
if builder.LocalInfo.Stack.ID != "io.buildpacks.stacks.jammy" {
context("using an older version of Ruby", func() {
it("pack builds and runs the app successfully", func() {
Expand Down

0 comments on commit af0f70e

Please sign in to comment.