2019-04-25 00:45:04 +03:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mono83/slf"
|
|
|
|
"github.com/mono83/slf/wd"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
)
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func paramsSliceToInterfaceSlice(params []slf.Param) []interface{} {
|
|
|
|
result := make([]interface{}, len(params))
|
|
|
|
for i, v := range params {
|
|
|
|
result[i], _ = v.(interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func prepareLoggerArgs(message string, params []slf.Param) []interface{} {
|
|
|
|
return append([]interface{}{message}, paramsSliceToInterfaceSlice(params)...)
|
|
|
|
}
|
|
|
|
|
2019-04-25 00:45:04 +03:00
|
|
|
type WdMock struct {
|
|
|
|
mock.Mock
|
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Trace(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Debug(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Info(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Warning(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Error(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Alert(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 02:29:14 +03:00
|
|
|
func (m *WdMock) Emergency(message string, params ...slf.Param) {
|
|
|
|
m.Called(prepareLoggerArgs(message, params)...)
|
2019-04-25 00:45:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *WdMock) IncCounter(name string, value int64, p ...slf.Param) {
|
|
|
|
m.Called(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *WdMock) UpdateGauge(name string, value int64, p ...slf.Param) {
|
|
|
|
m.Called(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *WdMock) RecordTimer(name string, d time.Duration, p ...slf.Param) {
|
|
|
|
m.Called(name, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *WdMock) Timer(name string, p ...slf.Param) slf.Timer {
|
|
|
|
return slf.NewTimer(name, p, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *WdMock) WithParams(p ...slf.Param) wd.Watchdog {
|
|
|
|
panic("this method shouldn't be used")
|
|
|
|
}
|