testing

package
Version: v0.0.0-...-538f495 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2014 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package testing provides fake implementations of the fs package.

These implementations can be used to mock out the file system in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FailureFs

type FailureFs struct {
	RecordingFs
	Err error
}

FailureFs is like RecordingFs, except the it returns an arbitrary error on operations.

func (*FailureFs) Open

func (r *FailureFs) Open(name string) (fs.File, error)

type FakeFile

type FakeFile struct {
	// contains filtered or unexported fields
}

FakeFile representss a fake instance of the File interface.

Methods from FakeFile act like methods in os.File, but instead of working in a real file, them work in an internal string.

An instance of FakeFile is returned by RecordingFs.Open method.

func (*FakeFile) Close

func (f *FakeFile) Close() error

func (*FakeFile) Fd

func (f *FakeFile) Fd() uintptr

func (*FakeFile) Read

func (f *FakeFile) Read(p []byte) (n int, err error)

func (*FakeFile) ReadAt

func (f *FakeFile) ReadAt(p []byte, off int64) (n int, err error)

func (*FakeFile) Seek

func (f *FakeFile) Seek(offset int64, whence int) (int64, error)

func (*FakeFile) Stat

func (f *FakeFile) Stat() (fi os.FileInfo, err error)

func (*FakeFile) Truncate

func (f *FakeFile) Truncate(size int64) error

func (*FakeFile) Write

func (f *FakeFile) Write(p []byte) (n int, err error)

func (*FakeFile) WriteString

func (f *FakeFile) WriteString(s string) (ret int, err error)

type FileNotFoundFs

type FileNotFoundFs struct {
	RecordingFs
}

FileNotFoundFs is like RecordingFs, except that it returns ENOENT on Open, OpenFile and Remove.

func (*FileNotFoundFs) Open

func (r *FileNotFoundFs) Open(name string) (fs.File, error)

func (*FileNotFoundFs) OpenFile

func (r *FileNotFoundFs) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

func (*FileNotFoundFs) Remove

func (r *FileNotFoundFs) Remove(name string) error

func (*FileNotFoundFs) RemoveAll

func (r *FileNotFoundFs) RemoveAll(path string) error

type RecordingFs

type RecordingFs struct {

	// FileContent is used to provide content for files opened using
	// RecordingFs.
	FileContent string
	// contains filtered or unexported fields
}

RecordingFs implements the Fs interface providing a "recording" file system.

A recording file system is a file system that does not execute any action, just record them.

All methods from RecordingFs never return errors.

func (*RecordingFs) Create

func (r *RecordingFs) Create(name string) (fs.File, error)

Create records the action "create <name>" and returns an instance of FakeFile and nil error.

func (*RecordingFs) HasAction

func (r *RecordingFs) HasAction(action string) bool

HasAction checks if a given action was executed in the filesystem.

For example, when you call the Open method with the "/tmp/file.txt" argument, RecordingFs will store locally the action "open /tmp/file.txt" and you can check it calling HasAction:

rfs.Open("/tmp/file.txt")
rfs.HasAction("open /tmp/file.txt") // true

func (*RecordingFs) Mkdir

func (r *RecordingFs) Mkdir(name string, perm os.FileMode) error

Mkdir records the action "mkdir <name> with mode <perm>" and returns nil.

func (*RecordingFs) MkdirAll

func (r *RecordingFs) MkdirAll(path string, perm os.FileMode) error

MkdirAll records the action "mkdirall <path> with mode <perm>" and returns nil.

func (*RecordingFs) Open

func (r *RecordingFs) Open(name string) (fs.File, error)

Open records the action "open <name>" and returns an instance of FakeFile and nil error.

func (*RecordingFs) OpenFile

func (r *RecordingFs) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

OpenFile records the action "openfile <name> with mode <perm>" and returns an instance of FakeFile and nil error.

func (*RecordingFs) Remove

func (r *RecordingFs) Remove(name string) error

Remove records the action "remove <name>" and returns nil.

func (*RecordingFs) RemoveAll

func (r *RecordingFs) RemoveAll(path string) error

RemoveAll records the action "removeall <path>" and returns nil.

func (*RecordingFs) Rename

func (r *RecordingFs) Rename(oldname, newname string) error

Rename records the action "rename <old> <new>" and returns nil.

func (*RecordingFs) Stat

func (r *RecordingFs) Stat(name string) (os.FileInfo, error)

Stat records the action "stat <name>" and returns nil, nil.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL