-
Notifications
You must be signed in to change notification settings - Fork 116
/
procfile_test.go
104 lines (82 loc) · 2.53 KB
/
procfile_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
package procfile_test
import (
"flag"
"fmt"
"os"
"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 TestProcfile(t *testing.T) {
Expect := NewWithT(t).Expect
Expect(len(builders)).NotTo(Equal(0))
SetDefaultEventuallyTimeout(60 * time.Second)
suite := spec.New("Procfile", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("Procfile with %s builder", builder), testProcfileWithBuilder(builder))
}
suite.Run(t)
}
func testProcfileWithBuilder(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 Procfile 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())
})
context("app uses a procfile", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source("../procfile/procfile-sample")
Expect(err).NotTo(HaveOccurred())
var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuilder(builder).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Procfile")))
container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(Serve(ContainSubstring("Hello World!")).OnPort(8080).WithEndpoint("/hello-world.txt"))
})
})
})
}
}