/
spam_logger.go
91 lines (83 loc) · 2.17 KB
/
spam_logger.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
88
89
90
91
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mocks
import (
"github.com/umputun/tg-spam/app/bot"
"sync"
)
// SpamLoggerMock is a mock implementation of events.SpamLogger.
//
// func TestSomethingThatUsesSpamLogger(t *testing.T) {
//
// // make and configure a mocked events.SpamLogger
// mockedSpamLogger := &SpamLoggerMock{
// SaveFunc: func(msg *bot.Message, response *bot.Response) {
// panic("mock out the Save method")
// },
// }
//
// // use mockedSpamLogger in code that requires events.SpamLogger
// // and then make assertions.
//
// }
type SpamLoggerMock struct {
// SaveFunc mocks the Save method.
SaveFunc func(msg *bot.Message, response *bot.Response)
// calls tracks calls to the methods.
calls struct {
// Save holds details about calls to the Save method.
Save []struct {
// Msg is the msg argument value.
Msg *bot.Message
// Response is the response argument value.
Response *bot.Response
}
}
lockSave sync.RWMutex
}
// Save calls SaveFunc.
func (mock *SpamLoggerMock) Save(msg *bot.Message, response *bot.Response) {
if mock.SaveFunc == nil {
panic("SpamLoggerMock.SaveFunc: method is nil but SpamLogger.Save was just called")
}
callInfo := struct {
Msg *bot.Message
Response *bot.Response
}{
Msg: msg,
Response: response,
}
mock.lockSave.Lock()
mock.calls.Save = append(mock.calls.Save, callInfo)
mock.lockSave.Unlock()
mock.SaveFunc(msg, response)
}
// SaveCalls gets all the calls that were made to Save.
// Check the length with:
//
// len(mockedSpamLogger.SaveCalls())
func (mock *SpamLoggerMock) SaveCalls() []struct {
Msg *bot.Message
Response *bot.Response
} {
var calls []struct {
Msg *bot.Message
Response *bot.Response
}
mock.lockSave.RLock()
calls = mock.calls.Save
mock.lockSave.RUnlock()
return calls
}
// ResetSaveCalls reset all the calls that were made to Save.
func (mock *SpamLoggerMock) ResetSaveCalls() {
mock.lockSave.Lock()
mock.calls.Save = nil
mock.lockSave.Unlock()
}
// ResetCalls reset all the calls that were made to all mocked methods.
func (mock *SpamLoggerMock) ResetCalls() {
mock.lockSave.Lock()
mock.calls.Save = nil
mock.lockSave.Unlock()
}