add tests for fswatcher package

This commit is contained in:
Dominic Breuker
2018-02-27 09:56:05 +01:00
committed by Dominic Breuker
parent 94a12cf031
commit 1deb4838a5
14 changed files with 277 additions and 199 deletions

View File

@@ -2,20 +2,18 @@ package fswatcher
import (
"fmt"
"github.com/dominicbreuker/pspy/internal/fswatcher/inotify"
)
func parseEvents(i *inotify.Inotify, dataCh chan []byte, eventCh chan string, errCh chan error) {
func parseEvents(i Inotify, dataCh chan []byte, eventCh chan string, errCh chan error) {
for buf := range dataCh {
var ptr uint32
for len(buf[ptr:]) > 0 {
event, size, err := i.ParseNextEvent(buf[ptr:])
ptr += size
if err != nil {
errCh <- fmt.Errorf("parsing events: %v", err)
continue
}
ptr += size
eventCh <- fmt.Sprintf("%20s | %s", event.Op, event.Name)
}
}