-
Notifications
You must be signed in to change notification settings - Fork 8
/
cache_handler_test.go
64 lines (51 loc) · 1.52 KB
/
cache_handler_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
package yarninstall_test
import (
"testing"
yarninstall "github.com/paketo-buildpacks/yarn-install"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testCacheHandler(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
cacheHandler yarninstall.CacheHandler
)
it.Before(func() {
cacheHandler = yarninstall.NewCacheHandler()
})
context("Match", func() {
var metadata map[string]interface{}
it.Before(func() {
metadata = map[string]interface{}{
"cache-sha": "some-sha",
}
})
context("when the layer metadata and choosen dependency shas match", func() {
it("it returns true and no error", func() {
match := cacheHandler.Match(metadata, "cache-sha", "some-sha")
Expect(match).To(BeTrue())
})
})
context("when the layer metadata and choosen dependency shas do not match", func() {
it("it returns false and no error", func() {
match := cacheHandler.Match(metadata, "cache-sha", "other-sha")
Expect(match).To(BeFalse())
})
})
context("when the layer metadata does not contain the dependency-sha", func() {
it("it returns false and no error", func() {
match := cacheHandler.Match(map[string]interface{}{}, "cache-sha", "some-sha")
Expect(match).To(BeFalse())
})
})
context("when the cache key has a type mismatch", func() {
it.Before(func() {
metadata["cache-sha"] = 10
})
it("returns false", func() {
match := cacheHandler.Match(metadata, "cache-sha", "some-sha")
Expect(match).To(BeFalse())
})
})
})
}