diff --git a/data_test.go b/data_test.go index 81ade81..ea02471 100644 --- a/data_test.go +++ b/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") diff --git a/embed_test.go b/embed_test.go index 99fc7cd..b721cbb 100644 --- a/embed_test.go +++ b/embed_test.go @@ -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")