-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfile_test.go
More file actions
67 lines (56 loc) · 1.51 KB
/
Copy pathfile_test.go
File metadata and controls
67 lines (56 loc) · 1.51 KB
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
65
66
67
package alephzero
import (
"os"
"testing"
)
func TestFile(t *testing.T) {
file, err := FileOpen("foo", nil)
check(t, err)
path := file.Path()
if path != "/dev/shm/foo" {
t.Errorf("file.Path() = %q, want foo", path)
}
fd := file.Fd()
if fd <= 2 {
t.Errorf("file.Fd() = %d, want > 2", fd)
}
arena := file.Arena()
if len(arena.Buf()) != 16*1024*1024 {
t.Errorf("len(file.Arena().Buf()) = %d, want 16MB", len(arena.Buf()))
}
check(t, file.Close())
if _, err := os.Stat("/dev/shm/foo"); os.IsNotExist(err) {
t.Errorf("/dev/shm/foo should exist")
}
check(t, FileRemove("foo"))
if _, err := os.Stat("/dev/shm/foo"); !os.IsNotExist(err) {
t.Errorf("/dev/shm/foo should not exist")
}
opts := MakeDefaultFileOptions()
opts.CreateOptions.Size = 1024
if opts.OpenOptions.ArenaMode != MODE_SHARED {
t.Errorf("opts.OpenOptions.ArenaMode = %d, want %d", opts.OpenOptions.ArenaMode, MODE_SHARED)
}
file, err = FileOpen("foo", &opts)
check(t, err)
path = file.Path()
if path != "/dev/shm/foo" {
t.Errorf("file.Path() = %q, want foo", path)
}
fd = file.Fd()
if fd <= 2 {
t.Errorf("file.Fd() = %d, want > 2", fd)
}
arena = file.Arena()
if len(arena.Buf()) != 1024 {
t.Errorf("len(file.Arena().Buf()) = %d, want 1kB", len(arena.Buf()))
}
check(t, file.Close())
if _, err = os.Stat("/dev/shm/foo"); os.IsNotExist(err) {
t.Errorf("/dev/shm/foo should exist")
}
check(t, FileRemove("foo"))
if _, err = os.Stat("/dev/shm/foo"); !os.IsNotExist(err) {
t.Errorf("/dev/shm/foo should not exist")
}
}