Skip to content

Commit

Permalink
Adds integration tests for Rake CNB
Browse files Browse the repository at this point in the history
- Adds Rake to order grouping

Co-authored-by: Frankie Gallina-Jones <frankieg@vmware.com>
  • Loading branch information
2 people authored and mergify[bot] committed Aug 11, 2020
1 parent 88ecabe commit 4fa0bda
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 0 deletions.
25 changes: 25 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,28 @@ api = "0.2"
id = "paketo-buildpacks/procfile"
version = "1.4.0"
optional = true

[[order]]

[[order.group]]
id = "paketo-community/mri"
version = "0.0.160"

[[order.group]]
id = "paketo-community/bundler"
version = "0.0.150"
optional = true

[[order.group]]
id = "paketo-community/bundle-install"
version = "0.0.57"
optional = true

[[order.group]]
id = "paketo-community/rake"
version = "0.0.3"

[[order.group]]
id = "paketo-buildpacks/procfile"
version = "1.4.0"
optional = true
1 change: 1 addition & 0 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestIntegration(t *testing.T) {
suite("Passenger", testPassenger)
suite("Puma", testPuma)
suite("Rackup", testRackup)
suite("Rake", testRake)
suite("Thin", testThin)
suite("Unicorn", testUnicorn)
suite.Run(t)
Expand Down
151 changes: 151 additions & 0 deletions integration/rake_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package integration_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func testRake(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
)

it.Before(func() {
pack = occam.NewPack()
docker = occam.NewDocker()
})

context("when building a rake container", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
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())
})

context("uses the rake gem", func() {
it("creates a working OCI image", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "rake"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithNoPull().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

container, err = docker.Container.Run.Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

rLogs := func() fmt.Stringer {
rakeLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return rakeLogs
}

Eventually(rLogs).Should(ContainSubstring("I am a rake task"))

Expect(logs).To(ContainLines(ContainSubstring("MRI Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Bundler Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Bundle Install Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Rake Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("bundle exec rake")))
})
})

context("does not use rake gem", func() {
it("creates a working OCI image", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "rake_no_gem"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithNoPull().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

container, err = docker.Container.Run.Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

rLogs := func() fmt.Stringer {
rakeLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return rakeLogs
}

Eventually(rLogs).Should(ContainSubstring("I am a rake task"))

Expect(logs).To(ContainLines(ContainSubstring("MRI Buildpack")))
Expect(logs).NotTo(ContainLines(ContainSubstring("Bundler Buildpack")))
Expect(logs).NotTo(ContainLines(ContainSubstring("Bundle Install Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Rake Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("rake")))
})
})

context("when there is a Procfile", func() {
it("creates a working OCI image that uses the start command from", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "rake"))
Expect(err).NotTo(HaveOccurred())
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: bundle exec rake proc"), 0644)).To(Succeed())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithNoPull().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

container, err = docker.Container.Run.Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

rLogs := func() fmt.Stringer {
rakeLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return rakeLogs
}

Eventually(rLogs).Should(ContainSubstring("I am the proc rake task"))

Expect(logs).To(ContainLines(ContainSubstring("MRI Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Bundler Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Bundle Install Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Rake Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Procfile Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("bundle exec rake proc")))
})
})
})
}
5 changes: 5 additions & 0 deletions integration/testdata/rake/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

ruby '~> 2.0'

gem 'rake'
9 changes: 9 additions & 0 deletions integration/testdata/rake/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
task :simple do
puts "I am a rake task"
end

task :default => [:simple]

task :proc do
puts "I am the proc rake task"
end
5 changes: 5 additions & 0 deletions integration/testdata/rake_no_gem/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
task :simple do
puts "I am a rake task"
end

task :default => [:simple]

0 comments on commit 4fa0bda

Please sign in to comment.