Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFakeWatcher

func NewFakeWatcher(changedFunc func(path string, added bool)) (NewFileWatcherFunc, *FakeWatcher)

NewFakeWatcher returns a function which creates a new fake watcher for unit testing. This allows observe callers to inject events and errors per-watched path. changedFunc() provides a callback notification when a new watch is added or removed. Production code should use `NewWatcher()`.

Types

type FakeWatcher

type FakeWatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FakeWatcher provides a fake file watcher implementation for unit tests. Production code should use the `NewWatcher()`.

func (*FakeWatcher) Add

func (w *FakeWatcher) Add(path string) error

Add is a fake implementation of the FileWatcher interface.

func (*FakeWatcher) Close

func (w *FakeWatcher) Close() error

Close is a fake implementation of the FileWatcher interface.

func (*FakeWatcher) Errors

func (w *FakeWatcher) Errors(path string) chan error

Errors is a fake implementation of the FileWatcher interface.

func (*FakeWatcher) Events

func (w *FakeWatcher) Events(path string) chan fsnotify.Event

Events is a fake implementation of the FileWatcher interface.

func (*FakeWatcher) InjectError

func (w *FakeWatcher) InjectError(path string, err error)

InjectError injects an error into the fake file watcher.

func (*FakeWatcher) InjectEvent

func (w *FakeWatcher) InjectEvent(path string, event fsnotify.Event)

InjectEvent injects an event into the fake file watcher.

func (*FakeWatcher) Remove

func (w *FakeWatcher) Remove(path string) error

Remove is a fake implementation of the FileWatcher interface.

type FileWatcher

type FileWatcher interface {
	Add(path string) error
	Remove(path string) error
	Close() error
	Events(path string) chan fsnotify.Event
	Errors(path string) chan error
}

FileWatcher is an interface that watches a set of files, delivering events to related channel.

func NewWatcher

func NewWatcher() FileWatcher

NewWatcher return with a FileWatcher instance that implemented with fsnotify.

type NewFileWatcherFunc

type NewFileWatcherFunc func() FileWatcher

NewFileWatcherFunc returns a functions which creates a new file watcher. This may be used to provide test hooks for using the FakeWatcher implementation below.