This commit is contained in:
Eugeny Leonov 2022-06-05 10:58:56 +05:00
parent 189b1d89af
commit 8a181bd909
2 changed files with 23 additions and 6 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
test
test/

View File

@ -1,7 +1,8 @@
package file
import (
"os"
"strconv"
"sync"
"testing"
)
@ -22,9 +23,25 @@ func TestFile(t *testing.T) {
}
func TestFileCreate(t *testing.T) {
f, err := OpenCreate("test/file.tst", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0664)
if err != nil {
t.Error(err)
if err := Save("test/test.txt", []byte("Test first string\n")); err != nil {
t.Error(err.Error())
}
f.Close()
if err := Append("test/test.txt", []byte("Test second string\n")); err != nil {
t.Error(err.Error())
}
//= Threaded write >
tw := &sync.WaitGroup{}
for ti := 0; ti < 10; ti++ {
tw.Add(1)
go func(ti int, t *testing.T) {
defer tw.Done()
for i := 0; i < 50; i++ {
if err := Append("test/test.txt", []byte("Thread "+strconv.Itoa(ti)+" line "+strconv.Itoa(i)+"\n")); err != nil {
t.Error(string(err.Code) + " " + err.Error())
}
}
}(ti, t)
}
tw.Wait()
//< Threaded write =
}