github.com/JFJun/bsc@v1.0.0/log/async_file_writer_test.go (about)

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