Documentation ¶
Overview ¶
package fakehttpfs provides a fake filesystem that implements the http.FileSystem interface.
To use it call the FileSystem function with one or more http.File objects. The File and Dir helper functions create files and directories respectively. For example:
testFS := fakehttpfs.FileSystem( fakehttpfs.File("/robots.txt", "User-agent: *\nDisallow: /"), fakehttpfs.Dir("/misc", fakehttpfs.File("hello.txt", "Hello", os.FileMode(0600)) os.Open("/path/to/some/real/file.txt") ) ); file, err := testFS.Open("/robots.txt") file, err := testFS.Open("/misc/file.txt")
Subdirectories need to be created with the Dir helper, but you do not have to use the File helper. If you'd like to write your own mock or stub or even use a real file you can.
The fake filesystem is not even slightly safe for concurrent use. By design concurrent calls to Open() with the same path will return the same file value (allowing you to test equality in your tests if needed). As a result the values will also share the same underlying io.ReadSeeker. Concurrent calls to file.Read() will give unpredictable results.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func File ¶
Creates a test fake file with string contents. If options includes a time.Time it is used to specify the file modification time, if not the zero time is used. Likewise, if options includes an os.FileMode it is used to specify the file mode, if not 0644 is used.
func FileSystem ¶
func FileSystem(files ...http.File) http.FileSystem
Creates a test fake filesystem containing the files.
Types ¶
This section is empty.