filesys

package
v0.0.0-...-d53c0b3 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package filesys contains abstractions and mocks of the file system, useful for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Creator

type Creator interface {
	// Create creates file `s` for writing. If the file already exists, it is truncated.
	Create(string) (io.WriteCloser, error)

	// WriteFile writes `data` to `file`. If the file doesn't exist, WriteFile creates it with `perm`.
	WriteFile(file string, data []byte, perm os.FileMode) error
}

Creator abstracts file creation from the filesystem. Used for testing.

type FS

type FS interface {
	Opener
	Creator
}

FS is the union of Opener and Creator

type MapFS

type MapFS map[string]string

MapFS is an in-memory implementation of FS, where all "files" are map entries, useful for testing.

func (MapFS) Create

func (fs MapFS) Create(s string) (io.WriteCloser, error)

Create implements Creator.Create. To emulate the actual filesystem, writes to the returned WriteCloser are not visible until the WriteCloser is Close()d.

func (MapFS) Open

func (fs MapFS) Open(s string) (io.ReadCloser, error)

Open returns a reader to a map entry. If the key `s` is not found, it returns an *os.PathError.

func (MapFS) ReadFile

func (fs MapFS) ReadFile(s string) ([]byte, error)

ReadFile returns the content of a map entry. If the key is not found, it returns an *os.PathError.

func (MapFS) WriteFile

func (fs MapFS) WriteFile(file string, data []byte, _ os.FileMode) error

WriteFile implements Creator.WriteFile.

type OS

type OS struct{}

OS implements Opener and Creator by delegating to os.

func (OS) Create

func (OS) Create(s string) (io.WriteCloser, error)

Create implements Creator.Create.

func (OS) Open

func (OS) Open(s string) (io.ReadCloser, error)

Open implements Opener.Open

func (OS) ReadFile

func (OS) ReadFile(s string) ([]byte, error)

ReadFile implements Opener.ReadFile

func (OS) WriteFile

func (OS) WriteFile(file string, data []byte, perm os.FileMode) error

WriteFile implements Creator.WriteFile.

type Opener

type Opener interface {
	// Open opens file `s` for reading.
	Open(string) (io.ReadCloser, error)

	// ReadFile reads the named file and returns the contents and any error encountered.
	ReadFile(string) ([]byte, error)
}

Opener abstracts reading from the filesystem. Used for testing.

Jump to

Keyboard shortcuts

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