-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect_test.go
89 lines (77 loc) · 2.48 KB
/
detect_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
package phpmemcachedhandler_test
import (
"errors"
"testing"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/servicebindings"
phpmemcachedhandler "github.com/paketo-buildpacks/php-memcached-session-handler"
"github.com/paketo-buildpacks/php-memcached-session-handler/fakes"
"github.com/sclevine/spec"
)
func testDetect(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
detectBindingResolver *fakes.DetectBindingResolver
detect packit.DetectFunc
)
it.Before(func() {
detectBindingResolver = &fakes.DetectBindingResolver{}
detectBindingResolver.ResolveCall.Returns.BindingSlice = []servicebindings.Binding{
{
Type: "php-memcached-session",
},
}
detect = phpmemcachedhandler.Detect(detectBindingResolver)
})
it("requires php during launch and provides nothing", func() {
result, err := detect(packit.DetectContext{
Platform: packit.Platform{
Path: "some-platform-path",
},
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Requires: []packit.BuildPlanRequirement{
{
Name: "php",
Metadata: phpmemcachedhandler.BuildPlanMetadata{
Launch: true,
},
},
},
Provides: []packit.BuildPlanProvision{},
}))
Expect(detectBindingResolver.ResolveCall.Receives.Typ).To(Equal("php-memcached-session"))
Expect(detectBindingResolver.ResolveCall.Receives.Provider).To(Equal(""))
Expect(detectBindingResolver.ResolveCall.Receives.PlatformDir).To(Equal("some-platform-path"))
})
context("there are no php-memcached-session bindings provided", func() {
it.Before(func() {
detectBindingResolver.ResolveCall.Returns.BindingSlice = []servicebindings.Binding{}
})
it("detection fails", func() {
_, err := detect(packit.DetectContext{
Platform: packit.Platform{
Path: "some-platform-path",
},
})
Expect(err).To(MatchError(packit.Fail.WithMessage("no service bindings of type `php-memcached-session` provided")))
})
})
context("failure cases", func() {
context("the binding resolver fails to resolve bindings", func() {
it.Before(func() {
detectBindingResolver.ResolveCall.Returns.Error = errors.New("failed to resolve bindings")
})
it("returns an error", func() {
_, err := detect(packit.DetectContext{
Platform: packit.Platform{
Path: "some-platform-path",
},
})
Expect(err).To(MatchError("failed to resolve bindings"))
})
})
})
}