github.com/replicatedhq/ship@v0.55.0/pkg/testing/tmpfs/tmp.go (about) 1 // in some cases we have to use a real os fs and not a mem map because of how Afero handles readdir on a file 2 package tmpfs 3 4 import ( 5 "io/ioutil" 6 "os" 7 "testing" 8 9 "github.com/spf13/afero" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func Tmpdir(t *testing.T) (string, func()) { 14 req := require.New(t) 15 d, err := ioutil.TempDir("", "gotest") 16 req.NoError(err) 17 18 return d, func() { 19 os.RemoveAll(d) 20 } 21 22 } 23 24 func Tmpfs(t *testing.T) (afero.Afero, func()) { 25 dir, cleanup := Tmpdir(t) 26 fs := afero.Afero{ 27 Fs: afero.NewBasePathFs(afero.NewOsFs(), dir), 28 } 29 return fs, cleanup 30 }