-
Notifications
You must be signed in to change notification settings - Fork 10
/
read_writer_test.go
64 lines (52 loc) · 1.14 KB
/
read_writer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// build linux
package iouring
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestReadWriterReadAt(t *testing.T) {
r, err := New(1024, &Params{
Features: FeatNoDrop,
})
require.NoError(t, err)
require.NotNil(t, r)
content := []byte("testing...1,2.3")
f, err := ioutil.TempFile("", "example")
require.NoError(t, err)
defer os.Remove(f.Name())
_, err = f.Write(content)
require.NoError(t, err)
require.NoError(t, f.Sync())
rw, err := r.FileReadWriter(f)
require.NoError(t, err)
buf := make([]byte, len(content)/2)
n, err := rw.ReadAt(buf, 0)
require.True(t,
n == len(buf),
"Excpected length %d, got: %d",
n,
len(buf),
)
}
func TestReadWriterWriteAt(t *testing.T) {
r, err := New(1024, &Params{
Features: FeatNoDrop,
})
require.NoError(t, err)
require.NotNil(t, r)
content := []byte("testing...1,2.3")
f, err := ioutil.TempFile("", "example")
require.NoError(t, err)
defer os.Remove(f.Name())
rw, err := r.FileReadWriter(f)
require.NoError(t, err)
n, err := rw.WriteAt(content, 0)
require.True(t,
n == len(content),
"Excpected length %d, got: %d",
n,
len(content),
)
}