forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifecycle_test.go
132 lines (109 loc) · 3.43 KB
/
lifecycle_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
package builder_test
import (
"archive/tar"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/heroku/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpacks/pack/internal/blob"
"github.com/buildpacks/pack/internal/builder"
h "github.com/buildpacks/pack/testhelpers"
)
func TestLifecycle(t *testing.T) {
color.Disable(true)
defer color.Disable(false)
spec.Run(t, "testLifecycle", testLifecycle, spec.Parallel(), spec.Report(report.Terminal{}))
}
func testLifecycle(t *testing.T, when spec.G, it spec.S) {
when("#NewLifecycle", func() {
when("there is a descriptor file with platform version 0.2", func() {
it("makes a lifecycle from a blob", func() {
lifecycle, err := builder.NewLifecycle(blob.NewBlob(filepath.Join("testdata", "lifecycle")))
h.AssertNil(t, err)
h.AssertEq(t, lifecycle.Descriptor().Info.Version.String(), "1.2.3")
h.AssertEq(t, lifecycle.Descriptor().API.PlatformVersion.String(), "0.2")
h.AssertEq(t, lifecycle.Descriptor().API.BuildpackVersion.String(), "0.3")
})
})
when("there is no descriptor file", func() {
it("throws an error ", func() {
_, err := builder.NewLifecycle(&fakeEmptyBlob{})
h.AssertError(t, err, "could not find entry path 'lifecycle.toml': not exist")
})
})
when("the lifecycle has incomplete list of binaries", func() {
var tmpDir string
it.Before(func() {
var err error
tmpDir, err = ioutil.TempDir("", "")
h.AssertNil(t, err)
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "lifecycle.toml"), []byte(`
[api]
platform = "0.2"
buildpack = "0.3"
[lifecycle]
version = "1.2.3"
`), os.ModePerm))
h.AssertNil(t, os.Mkdir(filepath.Join(tmpDir, "lifecycle"), os.ModePerm))
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "lifecycle", "analyzer"), []byte("content"), os.ModePerm))
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "lifecycle", "detector"), []byte("content"), os.ModePerm))
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "lifecycle", "builder"), []byte("content"), os.ModePerm))
})
it.After(func() {
h.AssertNil(t, os.RemoveAll(tmpDir))
})
it("returns an error", func() {
_, err := builder.NewLifecycle(blob.NewBlob(tmpDir))
h.AssertError(t, err, "validating binaries")
})
})
when("the lifecycle has platform version 0.1 and is missing cacher", func() {
var tmpDir string
it.Before(func() {
var err error
tmpDir, err = ioutil.TempDir("", "")
h.AssertNil(t, err)
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "lifecycle.toml"), []byte(`
[api]
platform = "0.1"
buildpack = "0.3"
[lifecycle]
version = "1.2.3"
`), os.ModePerm))
h.AssertNil(t, os.Mkdir(filepath.Join(tmpDir, "lifecycle"), os.ModePerm))
for _, f := range []string{
"detector",
"restorer",
"analyzer",
"builder",
"exporter",
"launcher",
} {
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "lifecycle", f), []byte("content"), os.ModePerm))
}
})
it.After(func() {
h.AssertNil(t, os.RemoveAll(tmpDir))
})
it("returns an error", func() {
_, err := builder.NewLifecycle(blob.NewBlob(tmpDir))
h.AssertError(t, err, "validating binaries")
})
})
})
}
type fakeEmptyBlob struct {
}
func (f *fakeEmptyBlob) Open() (io.ReadCloser, error) {
pr, pw := io.Pipe()
go func() {
defer pw.Close()
tw := tar.NewWriter(pw)
defer tw.Close()
}()
return pr, nil
}