mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 10:50:37 -06:00
a8eef45a44
* migrate log15 to gokit/log * fix console log * update some unittest * fix all unittest * fix the build * Update pkg/infra/log/log.go Co-authored-by: Yuriy Tseretyan <tceretian@gmail.com> * general type vector * correct the level key Co-authored-by: Yuriy Tseretyan <tceretian@gmail.com>
45 lines
924 B
Go
45 lines
924 B
Go
package log
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func (w *FileLogWriter) WriteLine(line string) error {
|
|
_, err := w.Write([]byte(line))
|
|
return err
|
|
}
|
|
|
|
func TestLogFile(t *testing.T) {
|
|
fileLogWrite := NewFileWriter()
|
|
require.NotNil(t, fileLogWrite)
|
|
|
|
t.Cleanup(func() {
|
|
err := fileLogWrite.Close()
|
|
assert.NoError(t, err)
|
|
err = os.Remove(fileLogWrite.Filename)
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
fileLogWrite.Filename = "grafana_test.log"
|
|
err := fileLogWrite.Init()
|
|
require.NoError(t, err)
|
|
|
|
assert.Zero(t, fileLogWrite.maxlinesCurlines)
|
|
|
|
t.Run("adding lines", func(t *testing.T) {
|
|
err := fileLogWrite.WriteLine("test1\n")
|
|
require.NoError(t, err)
|
|
err = fileLogWrite.WriteLine("test2\n")
|
|
require.NoError(t, err)
|
|
err = fileLogWrite.WriteLine("test3\n")
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, 3, fileLogWrite.maxlinesCurlines)
|
|
})
|
|
}
|