From 4fa0bda207b203371aa10989e6867c7f0bbebb0f Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 11 Aug 2020 17:21:35 -0400 Subject: [PATCH] Adds integration tests for Rake CNB - Adds Rake to order grouping Co-authored-by: Frankie Gallina-Jones --- buildpack.toml | 25 ++++ integration/init_test.go | 1 + integration/rake_test.go | 151 ++++++++++++++++++++++ integration/testdata/rake/Gemfile | 5 + integration/testdata/rake/Rakefile | 9 ++ integration/testdata/rake_no_gem/Rakefile | 5 + 6 files changed, 196 insertions(+) create mode 100644 integration/rake_test.go create mode 100644 integration/testdata/rake/Gemfile create mode 100644 integration/testdata/rake/Rakefile create mode 100644 integration/testdata/rake_no_gem/Rakefile diff --git a/buildpack.toml b/buildpack.toml index 69692ec3..ebb78847 100644 --- a/buildpack.toml +++ b/buildpack.toml @@ -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 diff --git a/integration/init_test.go b/integration/init_test.go index 7e12b017..af405d8c 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -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) diff --git a/integration/rake_test.go b/integration/rake_test.go new file mode 100644 index 00000000..04c06bc1 --- /dev/null +++ b/integration/rake_test.go @@ -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"))) + }) + }) + }) +} diff --git a/integration/testdata/rake/Gemfile b/integration/testdata/rake/Gemfile new file mode 100644 index 00000000..1758cd99 --- /dev/null +++ b/integration/testdata/rake/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +ruby '~> 2.0' + +gem 'rake' diff --git a/integration/testdata/rake/Rakefile b/integration/testdata/rake/Rakefile new file mode 100644 index 00000000..bf3ab79e --- /dev/null +++ b/integration/testdata/rake/Rakefile @@ -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 diff --git a/integration/testdata/rake_no_gem/Rakefile b/integration/testdata/rake_no_gem/Rakefile new file mode 100644 index 00000000..6400e9a4 --- /dev/null +++ b/integration/testdata/rake_no_gem/Rakefile @@ -0,0 +1,5 @@ +task :simple do + puts "I am a rake task" +end + +task :default => [:simple]