diff --git a/cmd/query/app/mocks/Watcher.go b/cmd/query/app/mocks/Watcher.go index 1cd05b0defc..50a3e361005 100644 --- a/cmd/query/app/mocks/Watcher.go +++ b/cmd/query/app/mocks/Watcher.go @@ -40,6 +40,20 @@ func (_m *Watcher) Add(name string) error { return r0 } +// Close provides a mock function with given fields: name +func (_m *Watcher) Close() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + // Errors provides a mock function with given fields: func (_m *Watcher) Errors() chan error { ret := _m.Called() diff --git a/pkg/config/tlscfg/cert_watcher.go b/pkg/config/tlscfg/cert_watcher.go index 5383e153e34..c03d87acb37 100644 --- a/pkg/config/tlscfg/cert_watcher.go +++ b/pkg/config/tlscfg/cert_watcher.go @@ -27,6 +27,8 @@ import ( "github.com/fsnotify/fsnotify" "go.uber.org/zap" + + "github.com/jaegertracing/jaeger/pkg/fswatcher" ) // certWatcher watches filesystem changes on certificates supplied via Options @@ -37,7 +39,7 @@ type certWatcher struct { mu sync.RWMutex opts Options logger *zap.Logger - watcher *fsnotify.Watcher + watcher fswatcher.Watcher cert *tls.Certificate caHash string clientCAHash string @@ -58,7 +60,7 @@ func newCertWatcher(opts Options, logger *zap.Logger) (*certWatcher, error) { cert = &c } - watcher, err := fsnotify.NewWatcher() + watcher, err := fswatcher.NewWatcher() if err != nil { return nil, err } @@ -148,7 +150,7 @@ func (w *certWatcher) setupWatchedPaths() error { func (w *certWatcher) watchChangesLoop(rootCAs, clientCAs *x509.CertPool) { for { select { - case event, ok := <-w.watcher.Events: + case event, ok := <-w.watcher.Events(): if !ok { return // channel closed means the watcher is closed } @@ -158,7 +160,7 @@ func (w *certWatcher) watchChangesLoop(rootCAs, clientCAs *x509.CertPool) { event.Op&fsnotify.Remove == fsnotify.Remove { w.attemptReload(rootCAs, clientCAs) } - case err, ok := <-w.watcher.Errors: + case err, ok := <-w.watcher.Errors(): if !ok { return // channel closed means the watcher is closed } diff --git a/pkg/config/tlscfg/cert_watcher_test.go b/pkg/config/tlscfg/cert_watcher_test.go index 0030ec7db18..cd36b4d46bd 100644 --- a/pkg/config/tlscfg/cert_watcher_test.go +++ b/pkg/config/tlscfg/cert_watcher_test.go @@ -23,12 +23,13 @@ import ( "testing" "time" - "github.com/fsnotify/fsnotify" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" + + "github.com/jaegertracing/jaeger/pkg/fswatcher" ) const ( @@ -340,7 +341,7 @@ func createTimestampDir(t *testing.T, dir string, ca, cert, key string) { } func TestAddCertsToWatch_err(t *testing.T) { - watcher, err := fsnotify.NewWatcher() + watcher, err := fswatcher.NewWatcher() require.NoError(t, err) defer watcher.Close() w := &certWatcher{ diff --git a/pkg/fswatcher/fs_watcher.go b/pkg/fswatcher/fs_watcher.go index 7c9c9aeec5b..ea61b967920 100644 --- a/pkg/fswatcher/fs_watcher.go +++ b/pkg/fswatcher/fs_watcher.go @@ -20,6 +20,7 @@ import "github.com/fsnotify/fsnotify" // Primarily used for mocking the fsnotify lib. type Watcher interface { Add(name string) error + Close() error Events() chan fsnotify.Event Errors() chan error } @@ -34,6 +35,11 @@ func (f *fsnotifyWatcherWrapper) Add(name string) error { return f.fsnotifyWatcher.Add(name) } +// Close closes the watcher. +func (f *fsnotifyWatcherWrapper) Close() error { + return f.fsnotifyWatcher.Close() +} + // Events returns the fsnotify.Watcher's Events chan. func (f *fsnotifyWatcherWrapper) Events() chan fsnotify.Event { return f.fsnotifyWatcher.Events diff --git a/pkg/fswatcher/fs_watcher_test.go b/pkg/fswatcher/fs_watcher_test.go index e4e630f8b10..b2ce42bc004 100644 --- a/pkg/fswatcher/fs_watcher_test.go +++ b/pkg/fswatcher/fs_watcher_test.go @@ -32,6 +32,9 @@ func TestFsWatcher(t *testing.T) { err = w.Add("../../cmd/query/app/fixture/ui-config.json") assert.NoError(t, err) + err = w.Close() + assert.NoError(t, err) + events := w.Events() assert.NotZero(t, events)