forked from cloudfoundry/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack_test.go
101 lines (84 loc) · 3.04 KB
/
pack_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
package dagger_test
import (
"os"
"path/filepath"
"testing"
"github.com/cloudfoundry/dagger"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testPack(t *testing.T, when spec.G, it spec.S) {
when("running pack", func() {
var tmpDir string
it.Before(func() {
tmpDir = os.TempDir()
var err error
tmpDir, err = filepath.EvalSymlinks(tmpDir)
Expect(err).ToNot(HaveOccurred())
})
it("should use default builder", func() {
packer := dagger.NewPack(tmpDir)
app, err := packer.Build()
Expect(err).NotTo(HaveOccurred())
Expect(app.BuildLogs()).To(ContainSubstring("pack build --builder cloudfoundry/cnb:cflinuxfs3]"))
})
it("should pack with given buildpacks and image-name", func() {
packer := dagger.NewPack(tmpDir,
dagger.SetBuildpacks("first-bp", "second-bp"),
dagger.SetImage("test-pack-image"),
)
app, err := packer.Build()
Expect(err).NotTo(HaveOccurred())
Expect(app.BuildLogs()).To(ContainSubstring("pack build test-pack-image --builder cloudfoundry/cnb:cflinuxfs3 --buildpack first-bp --buildpack second-bp]"))
})
it("should pack with given builder", func() {
packer := dagger.NewPack(tmpDir,
dagger.SetBuildpacks("first-bp", "second-bp"),
dagger.SetBuilder("bionic"),
)
app, err := packer.Build()
Expect(err).NotTo(HaveOccurred())
Expect(app.BuildLogs()).To(ContainSubstring("pack build --builder cloudfoundry/cnb:bionic --buildpack first-bp --buildpack second-bp]"))
})
it("should pack in offline containers", func() {
packer := dagger.NewPack(tmpDir,
dagger.SetBuildpacks("first-bp"),
dagger.SetImage("test-pack-image"),
dagger.SetOffline(),
)
app, err := packer.Build()
Expect(err).NotTo(HaveOccurred())
Expect(app.BuildLogs()).To(ContainSubstring("pack build test-pack-image --builder cloudfoundry/cnb:cflinuxfs3 --buildpack first-bp --no-pull --network none]"))
})
it("should pack with a given environment", func() {
packer := dagger.NewPack(tmpDir,
dagger.SetImage("test-pack-image"),
dagger.SetEnv(map[string]string{
"env1": "val1",
"env2": "val2",
}),
)
app, err := packer.Build()
Expect(err).NotTo(HaveOccurred())
Expect(app.BuildLogs()).To(ContainSubstring("pack build test-pack-image --builder cloudfoundry/cnb:cflinuxfs3 -e env1=val1 -e env2=val2]"))
})
it("should not pack with given builder that is not supported", func() {
packer := dagger.NewPack(tmpDir,
dagger.SetBuildpacks("first-bp", "second-bp"),
dagger.SetBuilder("not-supported"),
)
app, err := packer.Build()
Expect(err.Error()).To(ContainSubstring("please use either 'bionic' or 'cflinuxfs3' as input keys to SetBuilder"))
Expect(app).To(BeNil())
})
it("should pack with a no-pull flag", func() {
packer := dagger.NewPack(tmpDir,
dagger.SetImage("test-pack-image"),
dagger.NoPull(),
)
app, err := packer.Build()
Expect(err).NotTo(HaveOccurred())
Expect(app.BuildLogs()).To(ContainSubstring("pack build test-pack-image --builder cloudfoundry/cnb:cflinuxfs3 --no-pull]"))
})
})
}