From fea5d2567cf68eeba1dfe6e6e60473b8c3ab6156 Mon Sep 17 00:00:00 2001 From: Ralf Pannemans Date: Fri, 13 Sep 2024 15:07:47 +0200 Subject: [PATCH] Add integration test --- integration.json | 2 - integration/init_test.go | 6 +-- integration/npm_test.go | 51 ++++++++++++++++++++++ integration/testdata/node-gyp/index.js | 13 ++++++ integration/testdata/node-gyp/package.json | 17 ++++++++ 5 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 integration/testdata/node-gyp/index.js create mode 100644 integration/testdata/node-gyp/package.json diff --git a/integration.json b/integration.json index 443cced2..ccd77b98 100644 --- a/integration.json +++ b/integration.json @@ -1,8 +1,6 @@ { "ubi-nodejs-extension": "github.com/paketo-community/ubi-nodejs-extension", "builders": [ - "paketocommunity/builder-ubi-buildpackless-base", - "paketobuildpacks/builder:buildpackless-base", "paketobuildpacks/builder-jammy-buildpackless-base" ] } diff --git a/integration/init_test.go b/integration/init_test.go index d56e021f..4b43cf1a 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -59,9 +59,9 @@ func TestIntegration(t *testing.T) { SetDefaultEventuallyTimeout(10 * time.Second) suite := spec.New("Integration", spec.Parallel(), spec.Report(report.Terminal{})) - suite("NodeStart", testNodeStart) + // suite("NodeStart", testNodeStart) suite("NPM", testNPM) - suite("ReproducibleBuilds", testReproducibleBuilds) - suite("Yarn", testYarn) + // suite("ReproducibleBuilds", testReproducibleBuilds) + // suite("Yarn", testYarn) suite.Run(t) } diff --git a/integration/npm_test.go b/integration/npm_test.go index e533494e..4007844c 100644 --- a/integration/npm_test.go +++ b/integration/npm_test.go @@ -165,6 +165,57 @@ func testNPM(t *testing.T, context spec.G, it spec.S) { }) }) + context("when building a node app that uses npm, has a start script and node-gyp dependency", 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()) + source, err = occam.Source(filepath.Join("testdata", "node-gyp")) + 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()) + }) + + it("builds a working OCI image for an app ", func() { + var err error + var logs fmt.Stringer + image, logs, _ = pack.WithNoColor().Build. + WithExtensions(settings.Extensions.UbiNodejsExtension.Online). + WithBuildpacks(nodeBuildpack). + WithPullPolicy(pullPolicy). + Execute(name, source) + Expect(err).NotTo(HaveOccurred()) + + Expect(logs).To(ContainLines(ContainSubstring("umpulumpa"))) + + container, err = docker.Container.Run. + WithEnv(map[string]string{"PORT": "8080"}). + WithPublish("8080"). + WithPublishAll(). + Execute(image.ID) + Expect(err).NotTo(HaveOccurred()) + + Eventually(container, "5s").Should(BeAvailable()) + + response, err := http.Get(fmt.Sprintf("http://localhost:%s", container.HostPort("8080"))) + Expect(err).NotTo(HaveOccurred()) + Expect(response.StatusCode).To(Equal(http.StatusOK)) + }) + }) + context("when building a node app that uses npm, has a start script and flat working directory", func() { var ( image occam.Image diff --git a/integration/testdata/node-gyp/index.js b/integration/testdata/node-gyp/index.js new file mode 100644 index 00000000..5ba3b371 --- /dev/null +++ b/integration/testdata/node-gyp/index.js @@ -0,0 +1,13 @@ +const express = require('express') +const app = express() +const port = process.env.PORT || 8080 + +const features = require('cpu-features')(); + +app.get('/', (req, res) => { + res.send(features) +}) + +app.listen(port, () => { + console.log(`Example app listening on port ${port}`) +}) diff --git a/integration/testdata/node-gyp/package.json b/integration/testdata/node-gyp/package.json new file mode 100644 index 00000000..10676b19 --- /dev/null +++ b/integration/testdata/node-gyp/package.json @@ -0,0 +1,17 @@ +{ + "name": "simple_app", + "version": "0.0.0", + "description": "some app", + "main": "index.js", + "scripts": { + "start": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "dependencies": { + "cpu-features": "^0.0.4", + "express": "^4.18.2" + }, + "devDependencies": { + "node-gyp": "^9.3.1" + } + } \ No newline at end of file