test: logging test

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos A Becker 2021-10-12 10:51:55 -03:00 committed by Christian Rocha
parent 350b13cba7
commit e8289143a5
1 changed files with 29 additions and 0 deletions

29
logging_test.go Normal file
View File

@ -0,0 +1,29 @@
package tea
import (
"log"
"os"
"path/filepath"
"testing"
)
func TestLogToFile(t *testing.T) {
path := filepath.Join(t.TempDir(), "log.txt")
prefix := "logprefix"
f, err := LogToFile(path, prefix)
if err != nil {
t.Error(err)
}
log.SetFlags(log.Lmsgprefix)
log.Println("some test log")
if err := f.Close(); err != nil {
t.Error(err)
}
out, err := os.ReadFile(path)
if err != nil {
t.Error(err)
}
if string(out) != prefix+" some test log\n" {
t.Fatalf("wrong log msg: %q", string(out))
}
}