Skip to content

Commit

Permalink
test: logging test
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 authored and meowgorithm committed Oct 12, 2021
1 parent 1c651d9 commit 31de7f7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions logging_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
}

0 comments on commit 31de7f7

Please sign in to comment.