-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_mock_test.go
49 lines (45 loc) · 1.29 KB
/
test_mock_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
//go:build gautocloud_mock
// +build gautocloud_mock
package test_mock_test
import (
"github.com/cloudfoundry-community/gautocloud"
"github.com/cloudfoundry-community/gautocloud/loader/fake"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type FakeService struct {
Data string
}
type SecondFakeService struct {
Data string
}
var _ = Describe("TestMock", func() {
mockedLoader := gautocloud.Loader().(*fake.MockLoader)
Context("When injecting a config", func() {
var fakeService FakeService
BeforeEach(func() {
mockedLoader.EXPECT().Inject(gomock.Any()).Do(func(fakeService *FakeService) {
fakeService.Data = "data"
}).Return(nil)
})
It("should inject what user want", func() {
err := gautocloud.Inject(&fakeService)
Expect(err).NotTo(HaveOccurred())
Expect(fakeService.Data).To(Equal("data"))
})
})
Context("When injecting a second config", func() {
var fakeService SecondFakeService
BeforeEach(func() {
mockedLoader.EXPECT().Inject(gomock.Any()).Do(func(fakeService *SecondFakeService) {
fakeService.Data = "data"
}).Return(nil)
})
It("should inject what user want", func() {
err := gautocloud.Inject(&fakeService)
Expect(err).NotTo(HaveOccurred())
Expect(fakeService.Data).To(Equal("data"))
})
})
})