forked from rugwirobaker/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhermes_test.go
53 lines (41 loc) · 1.24 KB
/
hermes_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
package hermes_test
import (
"context"
"testing"
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
"github.com/quarksgroup/sms-client/sms"
"github.com/rugwirobaker/hermes"
"github.com/rugwirobaker/hermes/mock/mocksmc"
)
var noContext = context.Background()
func TestSend(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()
mockReport := &sms.Report{
ID: "fake_id",
Cost: 1,
}
mockToken := &sms.Token{}
mockSMS := &hermes.SMS{}
mockSendService := mocksmc.NewMockSendService(controller)
mockSendService.EXPECT().Send(gomock.Any(), gomock.Any()).Return(mockReport, nil, nil)
mockAuthService := mocksmc.NewMockAuthService(controller)
mockAuthService.EXPECT().Refresh(gomock.Any(), gomock.Any(), false).Return(mockToken, nil, nil)
mockAuthService.EXPECT().Login(gomock.Any(), "id", "secret").Return(mockToken, nil, nil)
client := new(sms.Client)
client.Message = mockSendService
client.Auth = mockAuthService
service, _ := hermes.NewSendService(client, "id", "secret", "sender", "callback")
want := &hermes.Report{
ID: "fake_id",
Cost: 1,
}
got, err := service.Send(noContext, mockSMS)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf(diff)
}
}