-
Notifications
You must be signed in to change notification settings - Fork 31
/
hooks_test.go
70 lines (59 loc) · 1.66 KB
/
hooks_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
package libbuildpack_test
import (
"errors"
bp "github.com/cloudfoundry/libbuildpack"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
//go:generate mockgen -source=hooks.go --destination=mocks_hooks_test.go --package=libbuildpack_test --imports=.=github.com/cloudfoundry/libbuildpack
var _ = Describe("Hooks", func() {
var (
mockCtrl *gomock.Controller
mockHook *MockHook
mockStager *bp.Stager
)
BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
mockHook = NewMockHook(mockCtrl)
mockStager = &bp.Stager{}
})
AfterEach(func() {
bp.ClearHooks()
})
Describe("RunBeforeCompile", func() {
It("Runs BeforeCompile on an added hook", func() {
mockHook.EXPECT().BeforeCompile(mockStager)
bp.AddHook(mockHook)
err := bp.RunBeforeCompile(mockStager)
Expect(err).To(Succeed())
})
It("Returns errors", func() {
mockHook.EXPECT().BeforeCompile(mockStager).Return(errors.New("err"))
bp.AddHook(mockHook)
err := bp.RunBeforeCompile(mockStager)
Expect(err).To(HaveOccurred())
})
})
Describe("RunAfterCompile", func() {
It("Runs AfterCompile on an added hook", func() {
mockHook.EXPECT().AfterCompile(mockStager)
bp.AddHook(mockHook)
err := bp.RunAfterCompile(mockStager)
Expect(err).To(Succeed())
})
It("Returns errors", func() {
mockHook.EXPECT().AfterCompile(mockStager).Return(errors.New("err"))
bp.AddHook(mockHook)
err := bp.RunAfterCompile(mockStager)
Expect(err).To(HaveOccurred())
})
})
Describe("DefaultHook", func() {
It("fulfils Hook interface", func() {
var hook bp.Hook
hook = bp.DefaultHook{}
Expect(hook).ToNot(BeNil())
})
})
})