-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathcontainer_test.go
More file actions
128 lines (107 loc) · 3.74 KB
/
container_test.go
File metadata and controls
128 lines (107 loc) · 3.74 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
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
package containers_test
import (
"os"
"path/filepath"
"github.com/cloudfoundry/java-buildpack/src/java/common"
"github.com/cloudfoundry/java-buildpack/src/java/containers"
"github.com/cloudfoundry/libbuildpack"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Container Registry", func() {
var (
ctx *common.Context
registry *containers.Registry
buildDir string
depsDir string
cacheDir string
)
BeforeEach(func() {
var err error
buildDir, err = os.MkdirTemp("", "build")
Expect(err).NotTo(HaveOccurred())
depsDir, err = os.MkdirTemp("", "deps")
Expect(err).NotTo(HaveOccurred())
cacheDir, err = os.MkdirTemp("", "cache")
Expect(err).NotTo(HaveOccurred())
// Create deps directory structure
err = os.MkdirAll(filepath.Join(depsDir, "0"), 0755)
Expect(err).NotTo(HaveOccurred())
logger := libbuildpack.NewLogger(os.Stdout)
manifest := &libbuildpack.Manifest{}
installer := &libbuildpack.Installer{}
stager := libbuildpack.NewStager([]string{buildDir, cacheDir, depsDir, "0"}, logger, manifest)
command := &libbuildpack.Command{}
ctx = &common.Context{
Stager: stager,
Manifest: manifest,
Installer: installer,
Log: logger,
Command: command,
}
registry = containers.NewRegistry(ctx)
})
AfterEach(func() {
os.RemoveAll(buildDir)
os.RemoveAll(depsDir)
os.RemoveAll(cacheDir)
})
Describe("Registry", func() {
BeforeEach(func() {
registry.Register(containers.NewSpringBootContainer(ctx))
registry.Register(containers.NewTomcatContainer(ctx))
registry.Register(containers.NewGroovyContainer(ctx))
registry.Register(containers.NewDistZipContainer(ctx))
registry.Register(containers.NewJavaMainContainer(ctx))
})
Context("with Spring Boot app", func() {
BeforeEach(func() {
os.MkdirAll(filepath.Join(buildDir, "BOOT-INF"), 0755)
// Create META-INF/MANIFEST.MF with Spring Boot markers
os.MkdirAll(filepath.Join(buildDir, "META-INF"), 0755)
manifest := "Manifest-Version: 1.0\nStart-Class: com.example.App\nSpring-Boot-Version: 2.7.0\n"
os.WriteFile(filepath.Join(buildDir, "META-INF", "MANIFEST.MF"), []byte(manifest), 0644)
})
It("detects Spring Boot container", func() {
container, name, err := registry.Detect()
Expect(err).NotTo(HaveOccurred())
Expect(container).NotTo(BeNil())
Expect(name).To(Equal("Spring Boot"))
})
})
Context("with no detectable app", func() {
It("returns nil container", func() {
container, name, err := registry.Detect()
Expect(err).NotTo(HaveOccurred())
Expect(container).To(BeNil())
Expect(name).To(BeEmpty())
})
})
})
Describe("DetectAll", func() {
It("returns all matching containers", func() {
// Create both Groovy and Tomcat (overlapping detection)
os.WriteFile(filepath.Join(buildDir, "app.groovy"), []byte("println 'hello'"), 0644)
os.MkdirAll(filepath.Join(buildDir, "WEB-INF"), 0755)
registry := containers.NewRegistry(ctx)
registry.Register(containers.NewGroovyContainer(ctx))
registry.Register(containers.NewTomcatContainer(ctx))
registry.Register(containers.NewJavaMainContainer(ctx))
detected, names, err := registry.DetectAll()
Expect(err).NotTo(HaveOccurred())
Expect(len(detected)).To(Equal(2))
Expect(len(names)).To(Equal(2))
Expect(names).To(ContainElement("Groovy"))
Expect(names).To(ContainElement("Tomcat"))
})
It("returns empty when no containers match", func() {
registry := containers.NewRegistry(ctx)
registry.Register(containers.NewSpringBootContainer(ctx))
registry.Register(containers.NewTomcatContainer(ctx))
detected, names, err := registry.DetectAll()
Expect(err).NotTo(HaveOccurred())
Expect(len(detected)).To(Equal(0))
Expect(len(names)).To(Equal(0))
})
})
})