test(core): cover embed root mount paths

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-03-24 20:20:19 +00:00
parent 98d078130e
commit d413e34097
2 changed files with 17 additions and 0 deletions

View file

@ -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")

View file

@ -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")