Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
c0d1ngm0nk3y committed Sep 13, 2024
1 parent dabd4b5 commit fea5d25
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
2 changes: 0 additions & 2 deletions integration.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
6 changes: 3 additions & 3 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
51 changes: 51 additions & 0 deletions integration/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions integration/testdata/node-gyp/index.js
Original file line number Diff line number Diff line change
@@ -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}`)
})
17 changes: 17 additions & 0 deletions integration/testdata/node-gyp/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit fea5d25

Please sign in to comment.