From 6739870f4d82df2150e988d2b17cfa2ee20889a1 Mon Sep 17 00:00:00 2001 From: Dominic Breuker Date: Wed, 14 Mar 2018 09:21:14 +0100 Subject: [PATCH] further extend inotify test --- internal/fswatcher/inotify/inotify_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/fswatcher/inotify/inotify_test.go b/internal/fswatcher/inotify/inotify_test.go index 2a21fad..09ddde1 100644 --- a/internal/fswatcher/inotify/inotify_test.go +++ b/internal/fswatcher/inotify/inotify_test.go @@ -4,17 +4,22 @@ import ( "fmt" "io/ioutil" "os" + "strings" "testing" "golang.org/x/sys/unix" ) func TestInotify(t *testing.T) { + // init + i := NewInotify() err := i.Init() expectNoError(t, err) + // add watchers + err = i.Watch("testdata/folder") expectNoError(t, err) @@ -23,6 +28,13 @@ func TestInotify(t *testing.T) { t.Errorf("Wrong error for non-existing-folder: got %v", err) } + numW := i.NumWatchers() + if numW != 1 { + t.Errorf("Expected 1 watcher but have %d", numW) + } + + // create and parse events + err = ioutil.WriteFile("testdata/folder/f1", []byte("file content"), 0644) expectNoError(t, err) defer os.Remove("testdata/folder/f1") @@ -43,8 +55,15 @@ func TestInotify(t *testing.T) { t.Fatalf("Wrong offset: %d", offset) } + // finish + err = i.Close() expectNoError(t, err) + + _, err = i.Read(buf) + if !strings.HasSuffix(fmt.Sprintf("%v", err), "errno: 9") { + t.Errorf("Wrong error for reading after close: got %v", err) + } } func expectNoError(t *testing.T, err error) {