filesystem

package
v2.2.0+incompatible Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	// CreateFile creates a new file. Returns error if provided parameter is directory.
	CreateFile(file string) error
	// ReadFile returns an content of given file
	ReadFile(file string) ([]byte, error)
	// WriteFile writes data to file
	WriteFile(file string, data []byte) error
	// FileExists returns true if given path was found
	FileExists(file string) bool
	// GetFiles takes a list of file system paths an returns a list of individual file paths
	GetFileNames(paths []string) ([]string, error)
	// Watch given paths, call 'onEvent' function on every event or 'onClose' if watcher is closed
	Watch(paths []string, onEvent func(event fsnotify.Event), onClose func()) error
	// Close allows to terminate watcher from outside which calls 'onClose'
	Close() error
}

API defines filesystem-related method with emphasis on the fileDB needs

type Handler

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

Handler is helper struct to manipulate with filesystem API

func NewFsHandler

func NewFsHandler() *Handler

NewFsHandler creates a new instance of file system handler

func (*Handler) Close

func (fsh *Handler) Close() error

Close the file watcher

func (*Handler) CreateFile

func (fsh *Handler) CreateFile(file string) error

CreateFile is an implementation of the file system API interface

func (*Handler) FileExists

func (fsh *Handler) FileExists(file string) bool

FileExists is an implementation of the file system API interface

func (*Handler) GetFileNames

func (fsh *Handler) GetFileNames(paths []string) (files []string, err error)

GetFileNames is an implementation of the file system API interface

func (*Handler) ReadFile

func (fsh *Handler) ReadFile(file string) ([]byte, error)

ReadFile is an implementation of the file system API interface

func (*Handler) Watch

func (fsh *Handler) Watch(paths []string, onEvent func(event fsnotify.Event), onClose func()) error

Watch starts new filesystem notification watcher. All events from files are passed to 'onEvent' function. Function 'onClose' is called when event channel is closed.

func (*Handler) WriteFile

func (fsh *Handler) WriteFile(file string, data []byte) error

WriteFile is an implementation of the file system API interface

type Mock

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

Mock allows to mock filesystem

func NewFileSystemMock

func NewFileSystemMock() *Mock

NewFileSystemMock creates new instance of the mock and initializes response list

func (*Mock) Close

func (mock *Mock) Close() error

Close closes channel for simulated events

func (*Mock) CreateFile

func (mock *Mock) CreateFile(file string) error

CreateFile mocks original method

func (*Mock) FileExists

func (mock *Mock) FileExists(file string) bool

FileExists mocks original method

func (*Mock) GetFileNames

func (mock *Mock) GetFileNames(paths []string) ([]string, error)

GetFileNames mocks original method

func (*Mock) ReadFile

func (mock *Mock) ReadFile(file string) ([]byte, error)

ReadFile mocks original method

func (*Mock) SendEvent

func (mock *Mock) SendEvent(event fsnotify.Event)

SendEvent allows to manually send events to mocked watcher

func (*Mock) Watch

func (mock *Mock) Watch(paths []string, onEvent func(event fsnotify.Event), onClose func()) error

Watch calls onEvent when event arrives and onClose when channel is closed

func (*Mock) When

func (mock *Mock) When(methodName string) *WhenResp

When defines name of the related method. It creates a new instance of WhenResp with provided method name and stores it to the mock.

func (*Mock) WriteFile

func (mock *Mock) WriteFile(file string, data []byte) error

WriteFile mocks original method

type WhenResp

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

WhenResp is helper struct with single method call and desired response items

func (*WhenResp) ThenReturn

func (when *WhenResp) ThenReturn(item ...interface{})

ThenReturn receives array of items, which are desired to be returned in mocked method defined in "When". The full logic is: - When('someMethod').ThenReturn('values')

Provided values should match return types of method. If method returns multiple values and only one is provided, mock tries to parse the value and returns it, while others will be nil or empty.

If method is called several times, all cases must be defined separately, even if the return value is the same: - When('method1').ThenReturn('val1') - When('method1').ThenReturn('val1')

All mocked methods are evaluated in same order they were assigned.

Jump to

Keyboard shortcuts

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