-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathgo_test.go
134 lines (107 loc) · 3.62 KB
/
go_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package go_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 TestGo(t *testing.T) {
Expect := NewWithT(t).Expect
Expect(len(builders)).NotTo(Equal(0))
SetDefaultEventuallyTimeout(60 * time.Second)
suite := spec.New("Go", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("Go with %s builder", builder), testGoWithBuilder(builder))
}
suite.Run(t)
}
func testGoWithBuilder(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 Go 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("no imports", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../go", "no-imports"))
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 Go Distribution")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Go Build")))
Expect(logs).NotTo(ContainLines(ContainSubstring("Paketo Buildpack for Go Mod Vendor")))
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("Powered By Paketo Buildpacks")).OnPort(8080))
})
})
context("uses go modules", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../go", "mod"))
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 Go Distribution")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Go Mod Vendor")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Go Build")))
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("Powered By Paketo Buildpacks")).OnPort(8080))
})
})
})
}
}