go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/supervisor/notify_provider.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package supervisor 9 10 import "github.com/rjeczalik/notify" 11 12 // FileEventProvider handles hooking up file event notifications. 13 type FileEventProvider interface { 14 Notify(string, chan notify.EventInfo) error 15 } 16 17 // NotifyProvider is the concrete notify provider. 18 type NotifyProvider struct{} 19 20 // Notify calls the underlying notification implemention. 21 func (np NotifyProvider) Notify(watchedPath string, fsevents chan notify.EventInfo) error { 22 return notify.Watch(watchedPath, fsevents, notify.All) 23 } 24 25 // MockNotifyProvider is a mocked notify provider. 26 type MockNotifyProvider struct { 27 watchedPaths []string 28 events chan notify.EventInfo 29 } 30 31 // Notify calls the underlying notification implemention. 32 func (mnp *MockNotifyProvider) Notify(watchedPath string, fsevents chan notify.EventInfo) error { 33 mnp.watchedPaths = append(mnp.watchedPaths, watchedPath) 34 mnp.events = fsevents 35 return nil 36 } 37 38 // Signal sends an event to the channel. 39 func (mnp *MockNotifyProvider) Signal(event notify.EventInfo) { 40 mnp.events <- event 41 }