forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpack_test.go
120 lines (98 loc) · 2.77 KB
/
buildpack_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
package builder_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/buildpack/pack/blob"
"github.com/fatih/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpack/pack/builder"
h "github.com/buildpack/pack/testhelpers"
)
func TestBuildpack(t *testing.T) {
color.NoColor = true
spec.Run(t, "buildpack", testBuildpack, spec.Parallel(), spec.Report(report.Terminal{}))
}
func testBuildpack(t *testing.T, when spec.G, it spec.S) {
var tmpBpDir string
it.Before(func() {
var err error
tmpBpDir, err = ioutil.TempDir("", "")
h.AssertNil(t, err)
})
it.After(func() {
h.AssertNil(t, os.RemoveAll(tmpBpDir))
})
when("#NewBuildpack", func() {
it("makes a buildpack from a blob", func() {
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpBpDir, "buildpack.toml"), []byte(`
api = "0.3"
[buildpack]
id = "bp.one"
version = "1.2.3"
[[stacks]]
id = "some.stack.id"
`), os.ModePerm))
bp, err := builder.NewBuildpack(blob.NewBlob(tmpBpDir))
h.AssertNil(t, err)
h.AssertEq(t, bp.Descriptor().API.String(), "0.3")
h.AssertEq(t, bp.Descriptor().Info.ID, "bp.one")
h.AssertEq(t, bp.Descriptor().Info.Version, "1.2.3")
h.AssertEq(t, bp.Descriptor().Stacks[0].ID, "some.stack.id")
})
when("there is no descriptor file", func() {
it("returns error", func() {
_, err := builder.NewBuildpack(blob.NewBlob(tmpBpDir))
h.AssertError(t, err, "could not find entry path 'buildpack.toml'")
})
})
when("there is no api field", func() {
it("assumes a version", func() {
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpBpDir, "buildpack.toml"), []byte(`
[buildpack]
id = "bp.one"
version = "1.2.3"
[[stacks]]
id = "some.stack.id"
`), os.ModePerm))
bp, err := builder.NewBuildpack(blob.NewBlob(tmpBpDir))
h.AssertNil(t, err)
h.AssertEq(t, bp.Descriptor().API.String(), "0.1")
})
})
when("both stacks and order are present", func() {
it.Before(func() {
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpBpDir, "buildpack.toml"), []byte(`
[buildpack]
id = "bp.one"
version = "1.2.3"
[[stacks]]
id = "some.stack.id"
[[order]]
[[order.group]]
id = "bp.nested"
version = "bp.nested.version"
`), os.ModePerm))
})
it("returns error", func() {
_, err := builder.NewBuildpack(blob.NewBlob(tmpBpDir))
h.AssertError(t, err, "cannot have both stacks and an order defined")
})
})
when("missing stacks and order", func() {
it.Before(func() {
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpBpDir, "buildpack.toml"), []byte(`
[buildpack]
id = "bp.one"
version = "1.2.3"
`), os.ModePerm))
})
it("returns error", func() {
_, err := builder.NewBuildpack(blob.NewBlob(tmpBpDir))
h.AssertError(t, err, "must have either stacks or an order defined")
})
})
})
}