gol/logger_test.go
Rinsvent e64e6eb2a3 Небольшой рефаткоринг
Удалил мусор
Добавил моки
Добавил тест
2024-09-24 23:24:06 +07:00

42 lines
938 B
Go

package gol
import (
"bou.ke/monkey"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
func TestLog(t *testing.T) {
now := time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC)
patch := monkey.Patch(time.Now, func() time.Time { return now })
defer patch.Unpatch()
t.Run("TestNilLog", func(t *testing.T) {
Info("info message")
//assert.Equal(t, test.expectedFileName, buildErrorsFilename(test.logFileName), "result")
})
t.Run("TestFileLog", func(t *testing.T) {
configPath := "test.log"
Init(&Configuration{
File: ConfigurationFile{
Enabled: true,
Level: "debug",
Filename: configPath,
},
})
Debug("Debug message")
Info("info message")
Warn("Warn message")
Error("Error message")
expectedFile, _ := os.ReadFile("data/test.log")
actualFile, _ := os.ReadFile("test.log")
assert.Equal(t, string(expectedFile), string(actualFile), "result")
os.Remove(configPath)
})
}