42 lines
938 B
Go
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)
|
||
|
})
|
||
|
}
|