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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package xtfs
import (
"embed"
"io"
"os"
"strings"
"testing"
)
var (
//go:embed _test/embed
embedded embed.FS
xtfs *XTFS
)
func TestMain(m *testing.M) {
var err error
xtfs, err = New("_test/disk", embedded, WithSub("_test/embed"), WithCaching(false))
if err != nil {
panic(err)
}
os.Exit(m.Run())
}
func TestEmbed(t *testing.T) {
fi, err := xtfs.Open("test1.txt")
if err != nil {
t.Log(err)
t.FailNow()
}
defer fi.Close()
test1, err := io.ReadAll(fi)
if err != nil {
t.Log(err)
t.FailNow()
}
if !strings.EqualFold(string(test1), "test1") {
t.Log("embed did not match")
t.FailNow()
}
}
func TestDisk(t *testing.T) {
fi, err := xtfs.Open("test2.txt")
if err != nil {
t.Log(err)
t.FailNow()
}
defer fi.Close()
test2, err := io.ReadAll(fi)
if err != nil {
t.Log(err)
t.FailNow()
}
if !strings.EqualFold(string(test2), "test3") {
t.Log("embed did not match")
t.FailNow()
}
}
func BenchmarkCache(b *testing.B) {
x, err := New("_test/disk", embedded)
if err != nil {
b.Log(err)
b.FailNow()
}
for idx := 0; idx < b.N; idx++ {
x.exists("test2.txt")
}
}
func BenchmarkNoCache(b *testing.B) {
x, err := New("_test/disk", embedded, WithCaching(false))
if err != nil {
b.Log(err)
b.FailNow()
}
for idx := 0; idx < b.N; idx++ {
x.exists("test2.txt")
}
}
|