-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuildpack_store_test.go
174 lines (146 loc) · 5.41 KB
/
buildpack_store_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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package occam_test
import (
"errors"
"testing"
"github.com/sclevine/spec"
"github.com/ForestEckhardt/freezer"
"github.com/paketo-buildpacks/occam"
"github.com/paketo-buildpacks/occam/fakes"
. "github.com/onsi/gomega"
)
func testBuildpackStore(t *testing.T, when spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
buildpackStore occam.BuildpackStore
fakeRemoteFetcher *fakes.RemoteFetcher
fakeLocalFetcher *fakes.LocalFetcher
fakeCacheManager *fakes.CacheManager
)
it.Before(func() {
fakeRemoteFetcher = &fakes.RemoteFetcher{}
fakeLocalFetcher = &fakes.LocalFetcher{}
fakeCacheManager = &fakes.CacheManager{}
buildpackStore = occam.NewBuildpackStore()
buildpackStore = buildpackStore.WithLocalFetcher(fakeLocalFetcher).
WithRemoteFetcher(fakeRemoteFetcher).
WithCacheManager(fakeCacheManager)
})
when("getting an online buildpack", func() {
when("from a local uri", func() {
it.Before(func() {
fakeLocalFetcher.GetCall.Returns.String = "/path/to/cool-buildpack/"
})
it("returns a local filepath to a buildpack", func() {
local_url, err := buildpackStore.Get.
WithVersion("some-version").
Execute("/some/local/path")
Expect(err).NotTo(HaveOccurred())
Expect(fakeCacheManager.OpenCall.CallCount).To(Equal(1))
Expect(fakeCacheManager.CloseCall.CallCount).To(Equal(1))
Expect(local_url).To(Equal("/path/to/cool-buildpack/"))
Expect(fakeRemoteFetcher.GetCall.CallCount).To(Equal(0))
Expect(fakeLocalFetcher.GetCall.CallCount).To(Equal(1))
Expect(fakeLocalFetcher.GetCall.Receives.LocalBuildpack).To(Equal(freezer.LocalBuildpack{
Path: "/some/local/path",
Name: "path",
UncachedKey: "path",
CachedKey: "path:cached",
Offline: false,
Version: "some-version",
}))
})
})
when("from a github uri", func() {
it.Before(func() {
fakeRemoteFetcher.GetCall.Returns.String = "/path/to/remote-buildpack/"
})
it("returns a local filepath to buildpack", func() {
local_url, err := buildpackStore.Get.
WithVersion("some-version").
Execute("github.com/some-org/some-repo")
Expect(err).NotTo(HaveOccurred())
Expect(fakeCacheManager.OpenCall.CallCount).To(Equal(1))
Expect(fakeCacheManager.CloseCall.CallCount).To(Equal(1))
Expect(local_url).To(Equal("/path/to/remote-buildpack/"))
Expect(fakeLocalFetcher.GetCall.CallCount).To(Equal(0))
Expect(fakeRemoteFetcher.GetCall.CallCount).To(Equal(1))
Expect(fakeRemoteFetcher.GetCall.Receives.RemoteBuildpack).To(Equal(freezer.RemoteBuildpack{
Org: "some-org",
Repo: "some-repo",
UncachedKey: "some-org:some-repo",
CachedKey: "some-org:some-repo:cached",
Offline: false,
Version: "some-version",
}))
})
})
when("Getting an offline buildpack", func() {
when("from a local uri", func() {
it.Before(func() {
fakeLocalFetcher.GetCall.Returns.String = "/path/to/cool-buildpack/"
})
it("returns a local filepath to a buildpack", func() {
local_url, err := buildpackStore.Get.
WithOfflineDependencies().
Execute("/some/local/path")
Expect(err).NotTo(HaveOccurred())
Expect(fakeCacheManager.OpenCall.CallCount).To(Equal(1))
Expect(fakeCacheManager.CloseCall.CallCount).To(Equal(1))
Expect(local_url).To(Equal("/path/to/cool-buildpack/"))
Expect(fakeRemoteFetcher.GetCall.CallCount).To(Equal(0))
Expect(fakeLocalFetcher.GetCall.CallCount).To(Equal(1))
Expect(fakeLocalFetcher.GetCall.Receives.LocalBuildpack).To(Equal(freezer.LocalBuildpack{
Path: "/some/local/path",
Name: "path",
UncachedKey: "path",
CachedKey: "path:cached",
Offline: true,
}))
})
})
when("from a github uri", func() {
it.Before(func() {
fakeRemoteFetcher.GetCall.Returns.String = "/path/to/remote-buildpack/"
})
it("returns a local filepath to a buildpack", func() {
local_url, err := buildpackStore.Get.
WithOfflineDependencies().
WithVersion("some-version").
Execute("github.com/some-org/some-repo")
Expect(err).NotTo(HaveOccurred())
Expect(fakeCacheManager.OpenCall.CallCount).To(Equal(1))
Expect(fakeCacheManager.CloseCall.CallCount).To(Equal(1))
Expect(local_url).To(Equal("/path/to/remote-buildpack/"))
Expect(fakeLocalFetcher.GetCall.CallCount).To(Equal(0))
Expect(fakeRemoteFetcher.GetCall.CallCount).To(Equal(1))
Expect(fakeRemoteFetcher.GetCall.Receives.RemoteBuildpack).To(Equal(freezer.RemoteBuildpack{
Org: "some-org",
Repo: "some-repo",
UncachedKey: "some-org:some-repo",
CachedKey: "some-org:some-repo:cached",
Offline: true,
Version: "some-version",
}))
})
})
})
})
when("failure cases", func() {
when("unable to open cacheManager", func() {
it.Before(func() {
fakeCacheManager.OpenCall.Returns.Error = errors.New("bad bad error")
})
it("returns an error", func() {
_, err := buildpackStore.Get.Execute("some-url")
Expect(err).To(MatchError("failed to open cacheManager: bad bad error"))
})
})
when("given an incomplete github.com url", func() {
it("returns an error", func() {
incompleteURL := "github.com/incomplete"
_, err := buildpackStore.Get.Execute(incompleteURL)
Expect(err).To(MatchError("error incomplete github.com url: \"github.com/incomplete\""))
})
})
})
}