-
Notifications
You must be signed in to change notification settings - Fork 5
/
packing_tools_test.go
119 lines (100 loc) · 3.54 KB
/
packing_tools_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
package freezer_test
import (
"errors"
"fmt"
"path/filepath"
"runtime"
"testing"
"github.com/ForestEckhardt/freezer"
"github.com/ForestEckhardt/freezer/fakes"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testPackingTools(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
executable *fakes.Executable
pack *fakes.Executable
tempOutput func(string, string) (string, error)
packingTools freezer.PackingTools
)
it.Before(func() {
executable = &fakes.Executable{}
pack = &fakes.Executable{}
tempOutput = func(string, string) (string, error) {
return "some-jam-output", nil
}
packingTools = freezer.NewPackingTools().WithExecutable(executable).WithPack(pack).WithTempOutput(tempOutput)
})
context("Execute", func() {
it("creates a correct pexec.Execution", func() {
err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", false)
Expect(err).NotTo(HaveOccurred())
Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"pack",
"--buildpack", filepath.Join("some-buildpack-dir", "buildpack.toml"),
"--output", filepath.Join("some-jam-output", "some-version.tgz"),
"--version", "some-version",
}))
Expect(pack.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"buildpack", "package",
"some-output",
"--path", filepath.Join("some-jam-output", "some-version.tgz"),
"--format", "file",
"--target", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}))
})
context("when cache is set to true", func() {
it("creates a correct pexec.Execution", func() {
err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true)
Expect(err).NotTo(HaveOccurred())
Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"pack",
"--buildpack", filepath.Join("some-buildpack-dir", "buildpack.toml"),
"--output", filepath.Join("some-jam-output", "some-version.tgz"),
"--version", "some-version",
"--offline",
}))
Expect(pack.ExecuteCall.Receives.Execution.Args).To(Equal([]string{
"buildpack", "package",
"some-output",
"--path", filepath.Join("some-jam-output", "some-version.tgz"),
"--format", "file",
"--target", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}))
})
})
context("failure cases", func() {
context("when the tempDir creation fails returns an error", func() {
it.Before(func() {
tempOutput = func(string, string) (string, error) {
return "", errors.New("some tempDir error")
}
packingTools = packingTools.WithTempOutput(tempOutput)
})
it("returns an error", func() {
err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true)
Expect(err).To(MatchError("some tempDir error"))
})
})
context("when the jam execution returns an error", func() {
it.Before(func() {
executable.ExecuteCall.Returns.Error = errors.New("some jam error")
})
it("returns an error", func() {
err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true)
Expect(err).To(MatchError("some jam error"))
})
})
context("when the pack execution returns an error", func() {
it.Before(func() {
pack.ExecuteCall.Returns.Error = errors.New("some pack error")
})
it("returns an error", func() {
err := packingTools.Execute("some-buildpack-dir", "some-output", "some-version", true)
Expect(err).To(MatchError("some pack error"))
})
})
})
})
}