Created
July 26, 2016 20:07
-
-
Save elevine/dfc5ccc68afbafd0c4857feebec83100 to your computer and use it in GitHub Desktop.
How to mock the filesystem in Go, from https://talks.golang.org/2012/10things.slide#8
This file contains hidden or 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
| var fs fileSystem = osFS{} | |
| type fileSystem interface { | |
| Open(name string) (file, error) | |
| Stat(name string) (os.FileInfo, error) | |
| } | |
| type file interface { | |
| io.Closer | |
| io.Reader | |
| io.ReaderAt | |
| io.Seeker | |
| Stat() (os.FileInfo, error) | |
| } | |
| // osFS implements fileSystem using the local disk. | |
| type osFS struct{} | |
| func (osFS) Open(name string) (file, error) { return os.Open(name) } | |
| func (osFS) Stat(name string) (os.FileInfo, error) { return os.Stat(name) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment