feat: test watcher
This commit is contained in:
@@ -13,6 +13,11 @@ type watcher struct {
|
||||
deploy pkgwatcher.DeployFunc
|
||||
}
|
||||
|
||||
var (
|
||||
errEventsClosedChan = errors.New("events is closed")
|
||||
errErrorsClosedChan = errors.New("errors is closed")
|
||||
)
|
||||
|
||||
func NewWatcher(deploy pkgwatcher.DeployFunc) *watcher {
|
||||
wt, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
@@ -36,8 +41,8 @@ func (w *watcher) Listen(binaryPath, scriptPath string, outputErr chan<- error)
|
||||
select {
|
||||
case event, ok := <-events:
|
||||
if !ok {
|
||||
log.Printf("!ok <-events \n")
|
||||
outputErr <- errors.New("!ok <-events")
|
||||
log.Println(errEventsClosedChan)
|
||||
outputErr <- errEventsClosedChan
|
||||
return
|
||||
}
|
||||
if !event.Has(fsnotify.Write) {
|
||||
@@ -47,14 +52,17 @@ func (w *watcher) Listen(binaryPath, scriptPath string, outputErr chan<- error)
|
||||
|
||||
if err := w.deploy(binaryPath, scriptPath); err != nil {
|
||||
log.Printf("deploy: %s\n", err)
|
||||
outputErr <- err
|
||||
continue
|
||||
}
|
||||
case err, ok := <-errChan:
|
||||
if !ok {
|
||||
log.Printf("!ok <-errors\n")
|
||||
log.Println(errErrorsClosedChan)
|
||||
outputErr <- errErrorsClosedChan
|
||||
return
|
||||
}
|
||||
log.Printf("<-errors: %s\n", err)
|
||||
outputErr <- err
|
||||
}
|
||||
}
|
||||
}(w.fswatcher.Events, w.fswatcher.Errors, outputErr)
|
||||
|
||||
Reference in New Issue
Block a user