-
Notifications
You must be signed in to change notification settings - Fork 17
/
vendored_test.go
135 lines (113 loc) · 3.63 KB
/
vendored_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package integration_test
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)
func testVendored(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().WithNoColor()
docker = occam.NewDocker()
})
context("when the node_modules are vendored", 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", "vendored"))
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 a simple app", func() {
var (
err error
logs fmt.Stringer
)
image, logs, err = pack.Build.
WithNoPull().
WithBuildpacks(
nodeURI,
buildpackURI,
buildPlanURI,
).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
container, err = docker.Container.Run.WithCommand("npm start").Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(BeAvailable())
response, err := http.Get(fmt.Sprintf("http://localhost:%s", container.HostPort()))
Expect(err).NotTo(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusOK))
content, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(ContainSubstring("Hello, World!"))
Expect(logs).To(ContainLines(
fmt.Sprintf("%s 1.2.3", buildpackInfo.Buildpack.Name),
" Resolving installation process",
" Process inputs:",
" node_modules -> \"Found\"",
" npm-cache -> \"Not found\"",
" package-lock.json -> \"Found\"",
"",
" Selected NPM build process: 'npm rebuild'",
"",
" Executing build process",
" Running 'npm run-script preinstall --if-present'",
MatchRegexp(` Running 'npm rebuild --nodedir=/layers/.+/node'`),
" Running 'npm run-script postinstall --if-present'",
MatchRegexp(` Completed in (\d+\.\d+|\d{3})`),
"",
" Configuring environment",
" NPM_CONFIG_LOGLEVEL -> \"error\"",
" NPM_CONFIG_PRODUCTION -> \"true\"",
fmt.Sprintf(" PATH -> \"$PATH:/layers/%s/modules/node_modules/.bin\"", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
))
})
context("when the npm and node buildpacks are cached", func() {
it("does not reach out to the internet", func() {
var err error
image, _, err = pack.Build.
WithNoPull().
WithBuildpacks(
nodeOfflineURI,
buildpackOfflineURI,
buildPlanURI,
).
WithNetwork("none").
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
container, err = docker.Container.Run.WithCommand("npm start").Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(BeAvailable())
response, err := http.Get(fmt.Sprintf("http://localhost:%s", container.HostPort()))
Expect(err).NotTo(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusOK))
})
})
})
}