Files
wazero/internal/testing/fs/fs_test.go
Crypt Keeper 798ff20f81 Removes WithWorkDirFS and "." resolution (#660)
This removes WithWorkDirFS and any other attempts to resolve the current directory (".") in host functions. This is a reaction to reality of compilers who track this inside wasm (not via host functions). One nice side effect is substantially simpler internal implementation of file-systems.

This also allows experimental.WithFS to block file access via passing nil.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-27 13:29:35 +08:00

39 lines
801 B
Go

package testfs
import (
"io/fs"
"testing"
"github.com/tetratelabs/wazero/internal/testing/require"
)
func TestFS(t *testing.T) {
testFS := &FS{}
t.Run("validates path", func(t *testing.T) {
f, err := testFS.Open("/foo.txt")
require.Nil(t, f)
require.EqualError(t, err, "open /foo.txt: invalid argument")
})
t.Run("path not found", func(t *testing.T) {
f, err := testFS.Open("foo.txt")
require.Nil(t, f)
require.EqualError(t, err, "open foo.txt: file does not exist")
})
(*testFS)["foo.txt"] = &File{}
f, err := testFS.Open("foo.txt")
require.NoError(t, err)
require.Equal(t, f, &File{})
}
func TestFile(t *testing.T) {
f := &File{CloseErr: fs.ErrClosed}
t.Run("returns close error", func(t *testing.T) {
err := f.Close()
require.Equal(t, fs.ErrClosed, err)
})
}