-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathspring_boot_test.go
More file actions
93 lines (81 loc) · 2.81 KB
/
Copy pathspring_boot_test.go
File metadata and controls
93 lines (81 loc) · 2.81 KB
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
package integration_test
import (
ctx "context"
"fmt"
"testing"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
func testSpringBoot(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
pack occam.Pack
docker occam.Docker
image occam.Image
container testcontainers.Container
buildLogs fmt.Stringer
)
it.Before(func() {
pack = occam.NewPack()
docker = occam.NewDocker()
})
it.After(func() {
Expect(container.Terminate(ctx.Background())).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
})
context("Maven", func() {
it("builds SpringBoot app from source with Maven", func() {
imageName, err := occam.RandomName()
Expect(err).ToNot(HaveOccurred())
image, buildLogs, err = pack.WithNoColor().Build.
WithBuildpacks(buildPack).
WithEnv(map[string]string{
"BP_ARCH": "amd64",
}).
WithBuilder(builder).
WithTrustBuilder().
WithPullPolicy("if-not-present").
Execute(imageName, "samples/java/maven")
Expect(err).ToNot(HaveOccurred())
Expect(buildLogs.String()).ToNot(BeEmpty())
Expect(len(image.Buildpacks)).To(BeNumerically(">", 0))
container, err = testContainers.WithExposedPorts("8080/tcp").WithWaitingFor(wait.ForLog("Started DemoApplication in")).Execute(imageName)
Expect(err).NotTo(HaveOccurred())
mappedPort, err := container.MappedPort(ctx.Background(), "8080/tcp")
Expect(err).ShouldNot(HaveOccurred())
resp, err := makeRequest("/actuator/health", mappedPort.Port())
Expect(err).ShouldNot(HaveOccurred())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(200))
})
})
context("Gradle", func() {
it("builds SpringBoot app from source with Gradle", func() {
imageName, err := occam.RandomName()
Expect(err).ToNot(HaveOccurred())
image, buildLogs, err = pack.WithNoColor().Build.
WithBuildpacks(buildPack).
WithEnv(map[string]string{
"BP_ARCH": "amd64",
}).
WithBuilder(builder).
WithTrustBuilder().
WithPullPolicy("if-not-present").
Execute(imageName, "samples/java/gradle")
Expect(err).ToNot(HaveOccurred())
Expect(buildLogs.String()).ToNot(BeEmpty())
Expect(len(image.Buildpacks)).To(BeNumerically(">", 0))
container, err = testContainers.WithExposedPorts("8080/tcp").WithWaitingFor(wait.ForLog("Started DemoApplication in")).Execute(imageName)
Expect(err).NotTo(HaveOccurred())
mappedPort, err := container.MappedPort(ctx.Background(), "8080/tcp")
Expect(err).ShouldNot(HaveOccurred())
resp, err := makeRequest("/actuator/health", mappedPort.Port())
Expect(err).ShouldNot(HaveOccurred())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(200))
})
})
}