mirror of
https://github.com/hanzoai/container.git
synced 2026-10-30 15:06:01 +00:00
* chore: move CGO_ENABLE arg to makefile * chore: use actual current executable path * chore: fix generated binary on M1 mac * net: fix #344 qemu process missing gvproxy config * chore: update gitignore * chore: refactor, mock filesystem in tests * chore: update nix environment * chore: refactor Makefile (#354) * refactor: extract build logic from build.sh to Makefile * chore: add test rule to Makefile * apply review suggestion Co-authored-by: Abiola Ibrahim <[email protected]> * fix: use defined `OUTPUT_DIR` variable * chore: remove -race flag from test as it needs CGO_ENABLED=1 * chore: generate sha in binaries directory * chore: propagate Go build environment variables Co-authored-by: Abiola Ibrahim <[email protected]> * chore: disable CGO * chore: remove empty file Co-authored-by: tricktron <[email protected]>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package fsutil
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"testing/fstest"
|
|
)
|
|
|
|
// FS is the host filesystem implementation.
|
|
var FS FileSystem = DefaultFS{}
|
|
|
|
// MkdirAll calls FS.MakedirAll
|
|
func MkdirAll(path string, perm os.FileMode) error { return FS.MkdirAll(path, perm) }
|
|
|
|
// Open calls FS.Open
|
|
func Open(name string) (fs.File, error) { return FS.Open(name) }
|
|
|
|
// FS is abstraction for filesystem.
|
|
type FileSystem interface {
|
|
MkdirAll(path string, perm os.FileMode) error
|
|
fs.FS
|
|
}
|
|
|
|
var _ FileSystem = DefaultFS{}
|
|
var _ FileSystem = fakeFS{}
|
|
|
|
// DefaultFS is the default OS implementation of FileSystem.
|
|
type DefaultFS struct{}
|
|
|
|
// Open implements FS
|
|
func (DefaultFS) Open(name string) (fs.File, error) { return os.Open(name) }
|
|
|
|
// MkdirAll implements FS
|
|
func (DefaultFS) MkdirAll(path string, perm fs.FileMode) error { return os.MkdirAll(path, perm) }
|
|
|
|
// FakeFS is a mock FS. The following can be done in a test before usage.
|
|
// osutil.FS = osutil.FakeFS
|
|
var FakeFS FileSystem = fakeFS{}
|
|
|
|
type fakeFS struct{}
|
|
|
|
// Open implements FileSystem
|
|
func (fakeFS) Open(name string) (fs.File, error) {
|
|
return fstest.MapFS{name: &fstest.MapFile{
|
|
Data: []byte("fake file - " + name),
|
|
}}.Open(name)
|
|
}
|
|
|
|
// MkdirAll implements FileSystem
|
|
func (fakeFS) MkdirAll(path string, perm fs.FileMode) error { return nil }
|