-
Notifications
You must be signed in to change notification settings - Fork 12
/
rebuild_test.go
106 lines (79 loc) · 2.5 KB
/
rebuild_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
package integration_test
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)
func testRebuild(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
pack occam.Pack
docker occam.Docker
imageIDs map[string]struct{}
containerIDs map[string]struct{}
name, source string
)
it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
pack = occam.NewPack().WithVerbose().WithNoColor()
docker = occam.NewDocker()
imageIDs = map[string]struct{}{}
containerIDs = map[string]struct{}{}
})
it.After(func() {
for id := range containerIDs {
Expect(docker.Container.Remove.Execute(id)).To(Succeed())
}
for id := range imageIDs {
Expect(docker.Image.Remove.Execute(id)).To(Succeed())
}
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})
context("when rebuilding an app", func() {
var firstImage, secondImage occam.Image
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "default"))
Expect(err).NotTo(HaveOccurred())
build := pack.Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.GoDist.Online,
settings.Buildpacks.GoBuild.Online,
)
var logs fmt.Stringer
firstImage, logs, err = build.Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
imageIDs[firstImage.ID] = struct{}{}
container, err := docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(firstImage.ID)
Expect(err).NotTo(HaveOccurred())
containerIDs[container.ID] = struct{}{}
Eventually(container).Should(BeAvailable())
secondImage, logs, err = build.Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
imageIDs[secondImage.ID] = struct{}{}
container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(secondImage.ID)
Expect(err).NotTo(HaveOccurred())
containerIDs[container.ID] = struct{}{}
Eventually(container).Should(BeAvailable())
Expect(secondImage.Buildpacks[1].Layers["targets"].SHA).To(Equal(firstImage.Buildpacks[1].Layers["targets"].SHA))
})
})
}