forked from paketo-community/ubi-base-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodejs_stack_integration_test.go
103 lines (81 loc) · 2.82 KB
/
nodejs_stack_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
package acceptance_test
import (
"fmt"
"os"
"path/filepath"
"regexp"
"testing"
"github.com/google/uuid"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/occam"
. "github.com/paketo-buildpacks/occam/matchers"
utils "github.com/paketo-community/ubi-base-stack/internal/utils"
)
func testNodejsStackIntegration(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
bpUbiRunImageOverrideImageID string
)
it.Before(func() {
pack = occam.NewPack().WithVerbose()
docker = occam.NewDocker()
})
context("When building an app with nodejs stacks", func() {
it.Before(func() {
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
source, err = occam.Source(filepath.Join("integration", "testdata", "nodejs_simple_app"))
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())
Expect(docker.Image.Remove.Execute(bpUbiRunImageOverrideImageID)).To(Succeed())
})
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 successfully builds an app using %s run image", stack.Name), func() {
runArchive := filepath.Join(root, stack.OutputDir, "run.oci")
bpUbiRunImageOverrideImageID, err = utils.PushFileToLocalRegistry(runArchive, RegistryUrl, fmt.Sprintf("run-%s-%s", stack.Name, uuid.NewString()))
Expect(err).NotTo(HaveOccurred())
image, _, err = pack.Build.
WithExtensions(
settings.Extensions.UbiNodejsExtension.Online,
).
WithBuildpacks(
settings.Buildpacks.Nodejs.Online,
).
WithBuilder(builder.imageUrl).
WithNetwork("host").
WithEnv(map[string]string{"BP_UBI_RUN_IMAGE_OVERRIDE": bpUbiRunImageOverrideImageID}).
WithPullPolicy("always").
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
container, err = docker.Container.Run.
WithPublish("8080").
WithCommand("npm start").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(Serve("Hello World!"))
nodejsMajorVersion := stack.Name[len("nodejs-"):]
Eventually(container).Should(Serve(MatchRegexp(fmt.Sprintf(`v%s.*`, nodejsMajorVersion))).OnPort(8080).WithEndpoint("/node/version"))
})
}
})
}