github.com/zooyer/miskit@v1.0.71/utils/io_test.go (about) 1 package utils 2 3 import ( 4 "io/ioutil" 5 "os" 6 "testing" 7 ) 8 9 func TestAppendFile(t *testing.T) { 10 var err error 11 const name = "test.txt" 12 defer os.Remove(name) 13 14 if err = Append(name, []byte("abc\n")); err != nil { 15 t.Fatal(err) 16 } 17 if err = Append(name, []byte("def\n")); err != nil { 18 t.Fatal(err) 19 } 20 if err = Append(name, []byte("ok\n")); err != nil { 21 t.Fatal(err) 22 } 23 data, err := ioutil.ReadFile(name) 24 if err != nil { 25 t.Fatal(err) 26 } 27 if string(data) != "abc\ndef\nok\n" { 28 t.Fatal("append file fail") 29 } 30 }