Documentation ¶
Index ¶
- type API
- type Handler
- func (fsh *Handler) Close() error
- func (fsh *Handler) CreateFile(file string) error
- func (fsh *Handler) FileExists(file string) bool
- func (fsh *Handler) GetFileNames(paths []string) (files []string, err error)
- func (fsh *Handler) ReadFile(file string) ([]byte, error)
- func (fsh *Handler) Watch(paths []string, onEvent func(event fsnotify.Event), onClose func()) error
- func (fsh *Handler) WriteFile(file string, data []byte) error
- type Mock
- func (mock *Mock) Close() error
- func (mock *Mock) CreateFile(file string) error
- func (mock *Mock) FileExists(file string) bool
- func (mock *Mock) GetFileNames(paths []string) ([]string, error)
- func (mock *Mock) ReadFile(file string) ([]byte, error)
- func (mock *Mock) SendEvent(event fsnotify.Event)
- func (mock *Mock) Watch(paths []string, onEvent func(event fsnotify.Event), onClose func()) error
- func (mock *Mock) When(methodName string) *WhenResp
- func (mock *Mock) WriteFile(file string, data []byte) error
- type WhenResp
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) CreateFile ¶
CreateFile is an implementation of the file system API interface
func (*Handler) FileExists ¶
FileExists is an implementation of the file system API interface
func (*Handler) GetFileNames ¶
GetFileNames is an implementation of the file system API interface
func (*Handler) ReadFile ¶
ReadFile is an implementation of the file system API interface
func (*Handler) Watch ¶
Watch starts new filesystem notification watcher. All events from files are passed to 'onEvent' function. Function 'onClose' is called when event channel is closed.
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) CreateFile ¶
CreateFile mocks original method
func (*Mock) FileExists ¶
FileExists mocks original method
func (*Mock) GetFileNames ¶
GetFileNames mocks original method
func (*Mock) ReadFile ¶
ReadFile mocks original method
func (*Mock) SendEvent ¶
SendEvent allows to manually send events to mocked watcher
func (*Mock) Watch ¶
Watch calls onEvent when event arrives and onClose when channel is closed
func (*Mock) When ¶
When defines name of the related method. It creates a new instance of WhenResp with provided method name and stores it to the mock.
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.