mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 03:34:50 +00:00
further extend inotify test
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user