forked from paketo-community/ubi-base-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildpack_integration_test.go
166 lines (134 loc) · 4.63 KB
/
buildpack_integration_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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package acceptance_test
import (
"fmt"
"os"
"path/filepath"
"regexp"
"testing"
utils "github.com/paketo-community/ubi-base-stack/internal/utils"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/occam"
. "github.com/paketo-buildpacks/occam/matchers"
)
func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
err error
pack occam.Pack
docker occam.Docker
source string
name string
image occam.Image
container occam.Container
runImageUrl string
builderImageUrl string
)
it.Before(func() {
pack = occam.NewPack().WithVerbose()
docker = occam.NewDocker()
})
context("When building an app using default stack", func() {
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())
err = utils.RemoveImages(docker, []string{runImageUrl, builderImageUrl})
Expect(err).NotTo(HaveOccurred())
Expect(os.RemoveAll(source)).To(Succeed())
})
it.Before(func() {
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
source, err = occam.Source(filepath.Join("integration", "testdata", "simple_app"))
Expect(err).NotTo(HaveOccurred())
})
for _, stack := range settings.ImagesJson.StackImages {
stack := stack
if stack.Name != "default" {
continue
}
it("should successfully build a go app", func() {
_, runImageUrl, builderImageUrl, err = utils.GenerateBuilder(root, "build", RegistryUrl)
Expect(err).NotTo(HaveOccurred())
image, _, err = pack.WithNoColor().Build.
WithBuildpacks(
settings.Buildpacks.GoDist.Online,
settings.Buildpacks.BuildPlan.Online,
).
WithEnv(map[string]string{
"BP_LOG_LEVEL": "DEBUG",
}).
WithPullPolicy("if-not-present").
WithBuilder(builderImageUrl).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
container, err = docker.Container.Run.
WithDirect().
WithCommand("go").
WithCommandArgs([]string{"run", "main.go"}).
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(BeAvailable())
Eventually(container).Should(Serve(MatchRegexp(`go1.*`)).OnPort(8080))
})
}
})
context("When building an app using Node.js stacks", func() {
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())
err = utils.RemoveImages(docker, []string{runImageUrl, builderImageUrl})
Expect(err).NotTo(HaveOccurred())
Expect(os.RemoveAll(source)).To(Succeed())
})
it.Before(func() {
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
source, err = occam.Source(filepath.Join("integration", "testdata", "simple_app"))
Expect(err).NotTo(HaveOccurred())
})
nodejsRegex, _ := regexp.Compile("^nodejs")
for _, stack := range settings.ImagesJson.StackImages {
// Create a copy of the stack to get the value instead of a pointer
stack := stack
if !nodejsRegex.MatchString(stack.Name) {
continue
}
it(fmt.Sprintf("it should successfully get the %s version of the run image", stack.Name), func() {
_, runImageUrl, builderImageUrl, err = utils.GenerateBuilder(root, stack.OutputDir, RegistryUrl)
Expect(err).NotTo(HaveOccurred())
image, _, err = pack.WithNoColor().Build.
WithBuildpacks(
settings.Buildpacks.GoDist.Online,
settings.Buildpacks.BuildPlan.Online,
).
WithEnv(map[string]string{
"BP_LOG_LEVEL": "DEBUG",
}).
WithPullPolicy("if-not-present").
WithBuilder(builderImageUrl).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
container, err = docker.Container.Run.
WithDirect().
WithCommand("go").
WithCommandArgs([]string{"run", "main.go"}).
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(BeAvailable())
Eventually(container).Should(Serve(MatchRegexp(`go1.*`)).OnPort(8080))
nodejsMajorVersion := stack.Name[len("nodejs-"):]
Eventually(container).Should(Serve(MatchRegexp(fmt.Sprintf(`v%s.*`, nodejsMajorVersion))).OnPort(8080).WithEndpoint("/nodejs/version"))
})
}
})
}