Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Oct 14, 2022
1 parent a3f7285 commit d9c468e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
44 changes: 42 additions & 2 deletions backend_windows_test.go
Expand Up @@ -53,6 +53,46 @@ func TestRemoveState(t *testing.T) {

// TODO: write test which makes sure the buffer size is set correctly.
func TestWindowsWithBufferSize(t *testing.T) {
w := newWatcher(t, t.TempDir())
fmt.Printf("%#v\n", w)
getWatch := func(opts ...addOpt) (*watch, error) {
w, err := NewWatcher()
if err != nil {
return nil, err
}
if err := w.AddWith(t.TempDir(), opts...); err != nil {
return nil, err
}

// Hackery to get first (and only) map value.
var v indexMap
for _, v = range w.watches {
}
if len(v) != 1 {
t.Fatal()
}
var watch *watch
for _, watch = range v {
}
return watch, nil
}

check := func(w *watch, want int) {
if len(w.buf) != want || cap(w.buf) != want {
t.Fatalf("want = %d; len = %d; cap = %d", want, len(w.buf), cap(w.buf))
}
}

if w, err := getWatch(); err != nil {
t.Fatal(err)
} else {
check(w, 65536)
}
if w, err := getWatch(WithBufferSize(4096)); err != nil {
t.Fatal(err)
} else {
check(w, 4096)
}

if _, err := getWatch(WithBufferSize(1024)); err == nil || !strings.Contains(err.Error(), "cannot be smaller") {
t.Fatal(err)
}
}
4 changes: 0 additions & 4 deletions fsnotify_test.go
Expand Up @@ -945,10 +945,6 @@ func TestAdd(t *testing.T) {
})
}

func TestAddWith(t *testing.T) {
// TODO: write basic test to ensure AddWith() isn't completely borked.
}

// TODO: should also check internal state is correct/cleaned up; e.g. no
// left-over file descriptors or whatnot.
func TestRemove(t *testing.T) {
Expand Down

0 comments on commit d9c468e

Please sign in to comment.