mirror of https://github.com/0xERR0R/blocky.git
42 lines
774 B
Go
42 lines
774 B
Go
package log
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus/hooks/test"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
func NewMockEntry() (*logrus.Entry, *MockLoggerHook) {
|
|
logger, _ := test.NewNullLogger()
|
|
logger.Level = logrus.TraceLevel
|
|
|
|
entry := logrus.Entry{Logger: logger}
|
|
hook := MockLoggerHook{}
|
|
|
|
entry.Logger.AddHook(&hook)
|
|
|
|
hook.On("Fire", mock.Anything).Return(nil)
|
|
|
|
return &entry, &hook
|
|
}
|
|
|
|
type MockLoggerHook struct {
|
|
mock.Mock
|
|
|
|
Messages []string
|
|
}
|
|
|
|
// Levels implements `logrus.Hook`.
|
|
func (h *MockLoggerHook) Levels() []logrus.Level {
|
|
return logrus.AllLevels
|
|
}
|
|
|
|
// Fire implements `logrus.Hook`.
|
|
func (h *MockLoggerHook) Fire(entry *logrus.Entry) error {
|
|
_ = h.Called()
|
|
|
|
h.Messages = append(h.Messages, entry.Message)
|
|
|
|
return nil
|
|
}
|