wa-lang.org/wazero@v1.0.2/internal/testing/fs/fs_test.go (about) 1 package testfs 2 3 import ( 4 "io/fs" 5 "testing" 6 7 "wa-lang.org/wazero/internal/testing/require" 8 ) 9 10 func TestFS(t *testing.T) { 11 testFS := &FS{} 12 13 t.Run("validates path", func(t *testing.T) { 14 f, err := testFS.Open("/foo.txt") 15 require.Nil(t, f) 16 require.EqualError(t, err, "open /foo.txt: invalid argument") 17 }) 18 19 t.Run("path not found", func(t *testing.T) { 20 f, err := testFS.Open("foo.txt") 21 require.Nil(t, f) 22 require.EqualError(t, err, "open foo.txt: file does not exist") 23 }) 24 25 (*testFS)["foo.txt"] = &File{} 26 f, err := testFS.Open("foo.txt") 27 require.NoError(t, err) 28 require.Equal(t, f, &File{}) 29 } 30 31 func TestFile(t *testing.T) { 32 f := &File{CloseErr: fs.ErrClosed} 33 34 t.Run("returns close error", func(t *testing.T) { 35 err := f.Close() 36 require.Equal(t, fs.ErrClosed, err) 37 }) 38 }