Skip to content

Instantly share code, notes, and snippets.

@abg
Created June 21, 2017 06:46
Show Gist options
  • Save abg/264a1de959107fb6190a2e58fc64906c to your computer and use it in GitHub Desktop.
Save abg/264a1de959107fb6190a2e58fc64906c to your computer and use it in GitHub Desktop.
package filesystem
// See: https://talks.golang.org/2012/10things.slide#1
// Also see github.com/spf13/afero
// Playground for testing some fake / TDD ideas around filesystem bits
// With https://github.com/maxbrunsfeld/counterfeiter can be used
// to Stub out various os.* bits to focus tests
import (
"io"
"os"
)
//go:generate counterfeiter . Filesystem
type Filesystem interface {
Open(name string) (File, error)
OpenFile(name string, flag int, perm os.FileMode) (File, error)
}
type File interface {
io.Closer
io.Reader
io.Writer
}
type localFilesystem struct{}
func (localFS *localFilesystem) Open(name string) (File, error) {
return os.Open(name)
}
func (localFS *localFilesystem) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
return os.OpenFile(name, flag, perm)
}
func NewLocalFilesystem() FileSystem {
return &localFilesystem{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment