Golang afero: Difference between revisions
From wikinotes
(→Basics) |
(→Basics) |
||
Line 25: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
There are no assertions, when testing use the API to check the presence/contents of the file. | There are no assertions, when testing use the API to check the presence/contents of the file.<br> | ||
There are however some additional utils that are helpful, both in testing and production code (ex. <code>appfs.DirExists()</code>). | |||
</blockquote><!-- Basics --> | </blockquote><!-- Basics --> | ||
</blockquote><!-- Usage --> | </blockquote><!-- Usage --> |
Revision as of 16:51, 22 July 2022
Afero defines and implements an interface to access the filesystem.
You can then pass in an abstraction of real os calls, or a stub stub interface you can make assertions against.
Documentation
github https://github.com/spf13/afero
Usage
Basics
import "github.com/spf13/afero" appfs := afero.NewOsFs() // real 'os' calls appfs := afero.NewMemMapFs() // memory backed fake filesystem // there are several additional options, like sftp, CopyOnWriteFs, ... appfs.Create("/var/tmp/foo.txt') // either creates on disk, or in memoryThere are no assertions, when testing use the API to check the presence/contents of the file.
There are however some additional utils that are helpful, both in testing and production code (ex.appfs.DirExists()
).