async_file_writer_test.go 430 B

1234567891011121314151617181920212223242526
  1. package log
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "strings"
  6. "testing"
  7. )
  8. func TestWriter(t *testing.T) {
  9. w := NewAsyncFileWriter("./hello.log", 100)
  10. w.Start()
  11. w.Write([]byte("hello\n"))
  12. w.Write([]byte("world\n"))
  13. w.Stop()
  14. files, _ := ioutil.ReadDir("./")
  15. for _, f := range files {
  16. fn := f.Name()
  17. if strings.HasPrefix(fn, "hello") {
  18. t.Log(fn)
  19. content, _ := ioutil.ReadFile(fn)
  20. t.Log(content)
  21. os.Remove(fn)
  22. }
  23. }
  24. }