fs

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NTIsPathSeparator

func NTIsPathSeparator(b byte) bool

NTIsPathSeparator returns true if and only if b is the ASCII code of a forward or backward slash.

func NTVolumeNameLength

func NTVolumeNameLength(s string) int

NTVolumeNameLength is similar to Go's "file/filepath".VolumeName, but is used to interpret the volume of a docker-compose service exactly like docker compose and interprets UNC paths and drive letters on non-Windows platforms. This function has the same logic as ntpath.splitdrive: https://github.com/python/cpython/blob/74510e2a57f6d4b51ac1ab4f778cd7a4c54b541e/Lib/ntpath.py#L116. Even on Windows we cannot use "file/filepath".VolumeName because it differs from Python's ntpath.splitdrive: 1. Go requires ASCII letter to precede colon for drive letters, but Python does not. 2. Go never considers paths that have a . after the third slash a UNC path, but Python does.

Types

type FileDescriptor

type FileDescriptor interface {
	io.ReadCloser
	Readdir(n int) ([]os.FileInfo, error)
}

FileDescriptor is an abstraction of os.File to improve testability of code.

type InMemoryFile

type InMemoryFile struct {
	Content   []byte
	Error     error
	Mode      os.FileMode
	OpenError error
	ReadError error
}

InMemoryFile is a helper struct used to initialize a file, directory or other type of file in a virtual file system. If Error is set then all file system operations will produce an error when the file is accessed. If Mode is a regular file then Content is the content of that file. If Mode is Symlink then Content is the location of the Symlink.

type InMemoryFileSystem

type InMemoryFileSystem struct {
	AbsError error

	GetwdError error
	// contains filtered or unexported fields
}

InMemoryFileSystem is a VirtualFileSystem with additional fields and functions useful for testing.

func NewInMemoryUnixFileSystem

func NewInMemoryUnixFileSystem(data map[string]InMemoryFile) *InMemoryFileSystem

NewInMemoryUnixFileSystem creates a mock file system based on the provided data.

func (*InMemoryFileSystem) Abs

func (fs *InMemoryFileSystem) Abs(name string) (string, error)

func (*InMemoryFileSystem) Chdir added in v0.6.1

func (fs *InMemoryFileSystem) Chdir(dir string) error
func (fs *InMemoryFileSystem) EvalSymlinks(path string) (string, error)

EvalSymlinks should behave the same as "path/filepath".EvalSymlinks, but on the virtual file system.

func (*InMemoryFileSystem) Getwd added in v0.6.1

func (fs *InMemoryFileSystem) Getwd() (string, error)

func (*InMemoryFileSystem) Lstat

func (fs *InMemoryFileSystem) Lstat(name string) (os.FileInfo, error)

Lstat should behave the same as os.Lstat but operates on the virtual file system.

func (*InMemoryFileSystem) Mkdir

func (fs *InMemoryFileSystem) Mkdir(name string, perm os.FileMode) error

func (*InMemoryFileSystem) MkdirAll

func (fs *InMemoryFileSystem) MkdirAll(name string, perm os.FileMode) error

func (*InMemoryFileSystem) Open

func (fs *InMemoryFileSystem) Open(name string) (FileDescriptor, error)
func (fs *InMemoryFileSystem) Readlink(name string) (string, error)

Readlink should behave the same as os.Readlink but operates on the virtual file system.

func (*InMemoryFileSystem) Set

func (fs *InMemoryFileSystem) Set(name string, vfile *InMemoryFile)

Set sets or updates the file at name. If one of the parents of name exists and is not a directory then the error ENOTDIR is returned. If a file already exists at name and it is a directory and vfile is not a directory (or vice versa) then an error is thrown. Otherwise, if a file already exists at name its attributes, injected fault, symlink target or regular file contents are updated with the values from vfile.

func (*InMemoryFileSystem) Stat

func (fs *InMemoryFileSystem) Stat(name string) (os.FileInfo, error)

type VirtualFileSystem

type VirtualFileSystem interface {
	Abs(name string) (string, error)
	Chdir(dir string) error
	EvalSymlinks(path string) (string, error)
	Getwd() (string, error)
	Mkdir(name string, perm os.FileMode) error
	MkdirAll(name string, perm os.FileMode) error
	Lstat(name string) (os.FileInfo, error)
	Open(name string) (FileDescriptor, error)
	Readlink(name string) (string, error)
	Stat(name string) (os.FileInfo, error)
}

VirtualFileSystem is an abstraction of the file system to improve testability of code.

var OS VirtualFileSystem = &osFileSystem{}

OS is a VirtualFileSystem that relays directly to Go's "os" and "file/filepath" packages. OS can be replaced by a mock VirtualFileSystem to improve testability of code using OS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL