forked from buildpacks/lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers_test.go
134 lines (116 loc) · 3.74 KB
/
handlers_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 lifecycle_test
import (
"os"
"path/filepath"
"testing"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpacks/lifecycle"
"github.com/buildpacks/lifecycle/buildpack"
h "github.com/buildpacks/lifecycle/testhelpers"
)
func TestHandlers(t *testing.T) {
spec.Run(t, "Handlers", testHandlers, spec.Report(report.Terminal{}))
}
func testHandlers(t *testing.T, when spec.G, it spec.S) {
var (
tmpDir string
groupTOMLContents string
expectedGroupBp []buildpack.GroupElement
expectedGroupExt []buildpack.GroupElement
orderTOMLContents string
expectedOrderBp buildpack.Order
expectedOrderExt buildpack.Order
)
it.Before(func() {
var err error
tmpDir, err = os.MkdirTemp("", "lifecycle.test")
h.AssertNil(t, err)
groupTOMLContents = `
[[group]]
id = "A" # intentionally missing version
api = "0.2"
[[group]]
id = "B"
version = "v1"
api = "0.3"
homepage = "bp-B-v1-homepage"
[[group-extensions]]
id = "B"
version = "v1"
api = "0.9"
homepage = "ext-B-v1-homepage"
`
expectedGroupBp = []buildpack.GroupElement{
{ID: "A", API: "0.2"},
{ID: "B", Version: "v1", API: "0.3", Homepage: "bp-B-v1-homepage"},
}
expectedGroupExt = []buildpack.GroupElement{
{ID: "B", Version: "v1", API: "0.9", Homepage: "ext-B-v1-homepage", Extension: true, Optional: true},
}
orderTOMLContents = `
[[order]]
group = [{id = "A", version = "v1"}, {id = "B", version = "v1", optional = true}]
[[order]]
group = [{id = "C", version = "v1"}]
[[order-extensions]]
group = [{id = "D", version = "v1"}]
`
expectedOrderBp = buildpack.Order{
{Group: []buildpack.GroupElement{{ID: "A", Version: "v1"}, {ID: "B", Version: "v1", Optional: true}}},
{Group: []buildpack.GroupElement{{ID: "C", Version: "v1"}}},
}
expectedOrderExt = buildpack.Order{
{Group: []buildpack.GroupElement{{ID: "D", Version: "v1", Extension: true, Optional: true}}},
}
})
it.After(func() {
os.RemoveAll(tmpDir)
})
when("#ReadGroup", func() {
it("returns a single group object with a buildpack group and an extensions group", func() {
h.Mkfile(t, groupTOMLContents, filepath.Join(tmpDir, "group.toml"))
foundGroup, err := lifecycle.ReadGroup(filepath.Join(tmpDir, "group.toml"))
h.AssertNil(t, err)
h.AssertEq(t, foundGroup, buildpack.Group{
Group: expectedGroupBp,
GroupExtensions: expectedGroupExt,
})
})
})
when("#ReadOrder", func() {
it("returns an ordering of buildpacks and an ordering of extensions", func() {
h.Mkfile(t, orderTOMLContents, filepath.Join(tmpDir, "order.toml"))
foundOrder, foundOrderExt, err := lifecycle.ReadOrder(filepath.Join(tmpDir, "order.toml"))
h.AssertNil(t, err)
h.AssertEq(t, foundOrder, expectedOrderBp)
h.AssertEq(t, foundOrderExt, expectedOrderExt)
})
})
when("DefaultConfigHandler", func() {
var (
configHandler *lifecycle.DefaultConfigHandler
)
it.Before(func() {
configHandler = lifecycle.NewConfigHandler()
})
when(".ReadGroup", func() {
it("returns a group for buildpacks and a group for extensions", func() {
h.Mkfile(t, groupTOMLContents, filepath.Join(tmpDir, "group.toml"))
foundGroup, foundGroupExt, err := configHandler.ReadGroup(filepath.Join(tmpDir, "group.toml"))
h.AssertNil(t, err)
h.AssertEq(t, foundGroup, expectedGroupBp)
h.AssertEq(t, foundGroupExt, expectedGroupExt)
})
})
when(".ReadOrder", func() {
it("returns an ordering of buildpacks and an ordering of extensions", func() {
h.Mkfile(t, orderTOMLContents, filepath.Join(tmpDir, "order.toml"))
foundOrder, foundOrderExt, err := configHandler.ReadOrder(filepath.Join(tmpDir, "order.toml"))
h.AssertNil(t, err)
h.AssertEq(t, foundOrder, expectedOrderBp)
h.AssertEq(t, foundOrderExt, expectedOrderExt)
})
})
})
}