The OsFS errors on double close whereas the MemMapFS does not. This leads to inconsistent behaviors between tests that use MemMapFS and production code that uses OsFS
package main
import (
"testing"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
)
func TestAferoMemMapFsDoubleClose(t *testing.T) {
fs := afero.NewMemMapFs()
f, err := fs.Create("test")
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)
err = f.Close()
assert.Error(t, err, "Should error on second close")
}
func TestAferoOsFSDoubleClose(t *testing.T) {
fs := afero.NewBasePathFs(afero.NewOsFs(), t.TempDir())
f, err := fs.Create("test")
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)
err = f.Close()
assert.Error(t, err, "Should error on second close")
}
The OsFS errors on double close whereas the MemMapFS does not. This leads to inconsistent behaviors between tests that use MemMapFS and production code that uses OsFS