-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
55 lines (45 loc) · 1.56 KB
/
client_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
package slackclient_test
import (
"context"
"github.com/golang/mock/gomock"
"github.com/incident-io/golang-client-mocking/slackclient"
mock_slackclient "github.com/incident-io/golang-client-mocking/slackclient/mock_slackclient"
"github.com/slack-go/slack"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ClientFor", func() {
var (
ctx context.Context
sc *mock_slackclient.MockSlackClient
)
BeforeEach(func() {
ctx = context.Background()
})
// Create a mock and assign it to the sc variable at the start of each test
slackclient.MockSlackClient(&ctx, &sc, nil)
Describe("mocking a channel call", func() {
// Apply an expectation in the BeforeEach, before the test runs
BeforeEach(func() {
sc.EXPECT().GetConversationInfoContext(gomock.Any(), "CH123", false).
Return(&slack.Channel{
GroupConversation: slack.GroupConversation{
Name: "my-channel",
Conversation: slack.Conversation{
NameNormalized: "my-channel",
ID: "CH123",
},
},
}, nil).Times(1)
})
Specify("returns a client that responds with the mock", func() {
client, err := slackclient.ClientFor(ctx, "OR123")
Expect(err).NotTo(HaveOccurred(), "Slack client should have built with no error")
channel, err := client.GetConversationInfoContext(ctx, "CH123", false)
Expect(err).NotTo(HaveOccurred())
// We'll only receive this if the client generated by ClientFor is the mock we
// configured with a fake response in our BeforeEach.
Expect(channel.NameNormalized).To(Equal("my-channel"))
})
})
})