Created
June 21, 2017 06:46
-
-
Save abg/264a1de959107fb6190a2e58fc64906c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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