forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifecycle_test.go
91 lines (76 loc) · 2.55 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
package builder_test
import (
"archive/tar"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/fatih/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpack/pack/blob"
"github.com/buildpack/pack/builder"
h "github.com/buildpack/pack/testhelpers"
)
func TestLifecycle(t *testing.T) {
color.NoColor = true
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() {
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("assumes 0.1 API versions", func() {
lifecycle, err := builder.NewLifecycle(&fakeEmptyBlob{})
h.AssertNil(t, err)
h.AssertEq(t, lifecycle.Descriptor().Info.Version.String(), "0.3.0")
h.AssertEq(t, lifecycle.Descriptor().API.PlatformVersion.String(), "0.1")
h.AssertEq(t, lifecycle.Descriptor().API.BuildpackVersion.String(), "0.1")
})
})
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")
})
})
})
}
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
}