|
| 1 | +package main_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "io/ioutil" |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/paketo-buildpacks/packit" |
| 10 | + "github.com/paketo-buildpacks/packit/scribe" |
| 11 | + main "github.com/paketo-community/rackup" |
| 12 | + "github.com/sclevine/spec" |
| 13 | + |
| 14 | + . "github.com/onsi/gomega" |
| 15 | +) |
| 16 | + |
| 17 | +func testBuild(t *testing.T, context spec.G, it spec.S) { |
| 18 | + var ( |
| 19 | + Expect = NewWithT(t).Expect |
| 20 | + |
| 21 | + layersDir string |
| 22 | + workingDir string |
| 23 | + cnbDir string |
| 24 | + buffer *bytes.Buffer |
| 25 | + |
| 26 | + build packit.BuildFunc |
| 27 | + ) |
| 28 | + |
| 29 | + it.Before(func() { |
| 30 | + var err error |
| 31 | + layersDir, err = ioutil.TempDir("", "layers") |
| 32 | + Expect(err).NotTo(HaveOccurred()) |
| 33 | + |
| 34 | + cnbDir, err = ioutil.TempDir("", "cnb") |
| 35 | + Expect(err).NotTo(HaveOccurred()) |
| 36 | + |
| 37 | + workingDir, err = ioutil.TempDir("", "working-dir") |
| 38 | + Expect(err).NotTo(HaveOccurred()) |
| 39 | + |
| 40 | + buffer = bytes.NewBuffer(nil) |
| 41 | + logger := scribe.NewLogger(buffer) |
| 42 | + |
| 43 | + build = main.Build(logger) |
| 44 | + }) |
| 45 | + |
| 46 | + it.After(func() { |
| 47 | + Expect(os.RemoveAll(layersDir)).To(Succeed()) |
| 48 | + Expect(os.RemoveAll(cnbDir)).To(Succeed()) |
| 49 | + Expect(os.RemoveAll(workingDir)).To(Succeed()) |
| 50 | + }) |
| 51 | + |
| 52 | + it("returns a result that provides a rackup start command", func() { |
| 53 | + result, err := build(packit.BuildContext{ |
| 54 | + WorkingDir: workingDir, |
| 55 | + CNBPath: cnbDir, |
| 56 | + Stack: "some-stack", |
| 57 | + BuildpackInfo: packit.BuildpackInfo{ |
| 58 | + Name: "Some Buildpack", |
| 59 | + Version: "some-version", |
| 60 | + }, |
| 61 | + Plan: packit.BuildpackPlan{ |
| 62 | + Entries: []packit.BuildpackPlanEntry{}, |
| 63 | + }, |
| 64 | + Layers: packit.Layers{Path: layersDir}, |
| 65 | + }) |
| 66 | + Expect(err).NotTo(HaveOccurred()) |
| 67 | + |
| 68 | + Expect(result).To(Equal(packit.BuildResult{ |
| 69 | + Plan: packit.BuildpackPlan{ |
| 70 | + Entries: nil, |
| 71 | + }, |
| 72 | + Layers: nil, |
| 73 | + Processes: []packit.Process{ |
| 74 | + { |
| 75 | + Type: "web", |
| 76 | + Command: "bundle exec rackup -p ${PORT}", |
| 77 | + }, |
| 78 | + }, |
| 79 | + })) |
| 80 | + |
| 81 | + Expect(buffer.String()).To(ContainSubstring("Some Buildpack some-version")) |
| 82 | + Expect(buffer.String()).To(ContainSubstring("Writing start command")) |
| 83 | + }) |
| 84 | +} |
0 commit comments