filewatcher

package
v0.0.0-...-687b63a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 22

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 {
	// Start watching a path. Calling Add multiple times on the same path panics.
	Add(path string) error

	// Stop watching a path. Removing a path that's not currently being watched panics.
	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 function which creates a new file watcher. This may be used to provide test hooks for using the FakeWatcher implementation below.

Jump to

Keyboard shortcuts

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