parent
86109c0f09
commit
57470b0615
67
xtfs_test.go
67
xtfs_test.go
|
@ -8,57 +8,66 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed _test/embed
|
||||
embedded embed.FS
|
||||
xtfs *XTFS
|
||||
)
|
||||
var embedded embed.FS
|
||||
|
||||
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")
|
||||
func TestXTFS(t *testing.T) {
|
||||
tt := []struct {
|
||||
Name string
|
||||
File string
|
||||
Expected string
|
||||
}{
|
||||
{
|
||||
Name: "Embed",
|
||||
File: "test1.txt",
|
||||
Expected: "test1",
|
||||
},
|
||||
{
|
||||
Name: "Disk",
|
||||
File: "test2.txt",
|
||||
Expected: "test3",
|
||||
},
|
||||
}
|
||||
|
||||
x, err := New("_test/disk", embedded, WithSub("_test/embed"), WithCaching(false))
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
fi, err := x.Open(tc.File)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.FailNow()
|
||||
}
|
||||
defer fi.Close()
|
||||
|
||||
test1, err := io.ReadAll(fi)
|
||||
contents, err := io.ReadAll(fi)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if !strings.EqualFold(string(test1), "test1") {
|
||||
t.Log("embed did not match")
|
||||
if !strings.EqualFold(string(contents), tc.Expected) {
|
||||
t.Logf("xtfs did not match:\n\tgot: %s\n\texpected: %s\n", string(contents), tc.Expected)
|
||||
t.FailNow()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisk(t *testing.T) {
|
||||
fi, err := xtfs.Open("test2.txt")
|
||||
var emptyFS embed.FS
|
||||
|
||||
func TestInvalid(t *testing.T) {
|
||||
_, err := New("/var/lib/myapp/assets/custom", emptyFS)
|
||||
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.Log("invalid XTFS should not error explicitly")
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue