forked from go-joe/joe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
48 lines (37 loc) · 982 Bytes
/
message_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
package joe
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestMessage_Respond(t *testing.T) {
a := new(MockAdapter)
msg := Message{adapter: a, Channel: "test"}
a.On("Send", "Hello world, The Answer is 42", "test").Return(nil)
msg.Respond("Hello %s, The Answer is %d", "world", 42)
a.AssertExpectations(t)
}
func TestMessage_RespondE(t *testing.T) {
a := new(MockAdapter)
msg := Message{adapter: a, Channel: "test"}
err := errors.New("a wild issue occurred")
a.On("Send", "Hello world", "test").Return(err)
actual := msg.RespondE("Hello world")
assert.Equal(t, err, actual)
a.AssertExpectations(t)
}
type MockAdapter struct {
mock.Mock
}
func (a *MockAdapter) RegisterAt(b *Brain) {
a.Called(b)
}
func (a *MockAdapter) Send(text, channel string) error {
args := a.Called(text, channel)
return args.Error(0)
}
func (a *MockAdapter) Close() error {
args := a.Called()
return args.Error(0)
}