1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package efitest
import (
"path/filepath"
"testing/fstest"
"github.com/foxboron/go-uefi/efi/fs"
"github.com/spf13/afero"
)
// Convert fstest.MapFS to afero.Fs
func FromMapFS(files fstest.MapFS) afero.Fs {
memfs := afero.NewMemMapFs()
for name, file := range files {
memfs.MkdirAll(filepath.Dir(name), 0644)
f, err := memfs.Create(name)
if err != nil {
continue
}
f.Write(file.Data)
f.Close()
}
return memfs
}
type FSState struct {
fs fstest.MapFS
}
func (f *FSState) ToAfero() afero.Fs {
return FromMapFS(f.fs)
}
func (f *FSState) SetFS() *FSState {
fs.SetFS(f.ToAfero())
return f
}
func (f *FSState) With(files ...fstest.MapFS) *FSState {
for _, mapfs := range files {
for path, file := range mapfs {
f.fs[path] = file
}
}
return f
}
func NewFS() *FSState {
return &FSState{fs: fstest.MapFS{}}
}
|