-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
common_test.go
87 lines (67 loc) · 1.56 KB
/
common_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package telego
import (
"fmt"
"sync"
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"github.com/mymmrac/telego/internal/json"
ta "github.com/mymmrac/telego/telegoapi"
mockapi "github.com/mymmrac/telego/telegoapi/mock"
)
var (
data = &ta.RequestData{}
emptyResp = &ta.Response{
Ok: true,
}
expectedMessage = &Message{
MessageID: 1,
}
testPortStart = 3100
testPortLock = sync.Mutex{}
)
func testAddress(t *testing.T) string {
t.Helper()
testPortLock.Lock()
defer testPortLock.Unlock()
testPortStart++
return fmt.Sprintf("127.0.0.1:%d", testPortStart)
}
func telegoResponse(t *testing.T, v any) *ta.Response {
t.Helper()
byteData, err := json.Marshal(v)
require.NoError(t, err)
return &ta.Response{
Ok: true,
Result: byteData,
}
}
type mockedBot struct {
MockAPICaller *mockapi.MockCaller
MockRequestConstructor *mockapi.MockRequestConstructor
Bot *Bot
}
func newMockedBot(ctrl *gomock.Controller) mockedBot {
mb := mockedBot{
MockAPICaller: mockapi.NewMockCaller(ctrl),
MockRequestConstructor: mockapi.NewMockRequestConstructor(ctrl),
}
//nolint:errcheck
bot, _ := NewBot(token,
WithAPICaller(mb.MockAPICaller),
WithRequestConstructor(mb.MockRequestConstructor),
WithDiscardLogger(),
WithWarnings())
mb.Bot = bot
return mb
}
type testNamedReade struct{}
func (t testNamedReade) Read(_ []byte) (n int, err error) {
panic("implement me")
}
func (t testNamedReade) Name() string {
return "test"
}
var testInputFile = InputFile{
File: testNamedReade{},
}