forked from paketo-buildpacks/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava_native_image_test.go
109 lines (87 loc) · 2.94 KB
/
java_native_image_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
package java_test
import (
"flag"
"fmt"
"os"
"path/filepath"
"testing"
"time"
"github.com/paketo-buildpacks/occam"
"github.com/paketo-buildpacks/samples/tests"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)
var builders tests.BuilderFlags
var suite spec.Suite
func init() {
flag.Var(&builders, "name", "the name a builder to test with")
}
func TestJNI(t *testing.T) {
Expect := NewWithT(t).Expect
Expect(len(builders)).NotTo(Equal(0))
SetDefaultEventuallyTimeout(60 * time.Second)
suite := spec.New("JavaNativeImage", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("Java Native Image with %s builder", builder), testJNIWithBuilder(builder), spec.Sequential())
}
suite.Run(t)
}
func testJNIWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
return func(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().WithVerbose().WithNoColor()
docker = occam.NewDocker()
})
context("detects a Java Native Image app", 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())
})
it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join(".", "java-native-image-sample"))
Expect(err).NotTo(HaveOccurred())
var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuilder(builder).
WithEnv(map[string]string{"BP_NATIVE_IMAGE": "true"}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(BeAvailable())
Expect(logs).To(ContainLines(ContainSubstring("Paketo GraalVM Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Maven Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Executable JAR Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Spring Boot Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Native Image Buildpack")))
Eventually(container).Should(Serve(ContainSubstring("UP")).OnPort(8080).WithEndpoint("/actuator/health"))
})
})
}
}