test(core): cover embed root mount paths
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
98d078130e
commit
d413e34097
2 changed files with 17 additions and 0 deletions
10
data_test.go
10
data_test.go
|
|
@ -9,6 +9,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// testFS exposes a filesystem rooted at ".", with testdata/ as a real directory entry.
|
||||
//
|
||||
//go:embed testdata
|
||||
var testFS embed.FS
|
||||
|
||||
|
|
@ -46,6 +48,14 @@ func TestData_ReadString_Good(t *testing.T) {
|
|||
assert.Equal(t, "hello from testdata\n", r.Value.(string))
|
||||
}
|
||||
|
||||
func TestData_ReadString_RootMount_Good(t *testing.T) {
|
||||
c := New().Value.(*Core)
|
||||
c.Data().New(Options{{Key: "name", Value: "app"}, {Key: "source", Value: testFS}, {Key: "path", Value: "."}})
|
||||
r := c.Data().ReadString("app/testdata/test.txt")
|
||||
assert.True(t, r.OK)
|
||||
assert.Equal(t, "hello from testdata\n", r.Value.(string))
|
||||
}
|
||||
|
||||
func TestData_ReadString_Bad(t *testing.T) {
|
||||
c := New().Value.(*Core)
|
||||
r := c.Data().ReadString("nonexistent/file.txt")
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ func TestEmbed_ReadString_Good(t *testing.T) {
|
|||
assert.Equal(t, "hello from testdata\n", r.Value.(string))
|
||||
}
|
||||
|
||||
func TestEmbed_ReadString_RootMount_Good(t *testing.T) {
|
||||
emb := Mount(testFS, ".").Value.(*Embed)
|
||||
r := emb.ReadString("testdata/test.txt")
|
||||
assert.True(t, r.OK)
|
||||
assert.Equal(t, "hello from testdata\n", r.Value.(string))
|
||||
}
|
||||
|
||||
func TestEmbed_Open_Good(t *testing.T) {
|
||||
emb := Mount(testFS, "testdata").Value.(*Embed)
|
||||
r := emb.Open("test.txt")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue