github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/testing/fs/fs_test.go (about)

     1  package testfs
     2  
     3  import (
     4  	"io/fs"
     5  	"testing"
     6  
     7  	"github.com/bananabytelabs/wazero/internal/testing/require"
     8  )
     9  
    10  func TestFS(t *testing.T) {
    11  	testFS := &FS{}
    12  
    13  	t.Run("path not found", func(t *testing.T) {
    14  		f, err := testFS.Open("foo.txt")
    15  		require.Nil(t, f)
    16  		require.EqualError(t, err, "open foo.txt: file does not exist")
    17  	})
    18  
    19  	(*testFS)["foo.txt"] = &File{}
    20  	f, err := testFS.Open("foo.txt")
    21  	require.NoError(t, err)
    22  	require.Equal(t, f, &File{})
    23  }
    24  
    25  func TestFile(t *testing.T) {
    26  	f := &File{CloseErr: fs.ErrClosed}
    27  
    28  	t.Run("returns close error", func(t *testing.T) {
    29  		err := f.Close()
    30  		require.Equal(t, fs.ErrClosed, err)
    31  	})
    32  }