1 Star 0 Fork 0

butnet/fsnotify

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
backend_kqueue_test.go 2.42 KB
一键复制 编辑 原始数据 按行查看 历史
Martin Tournoij 提交于 2022-10-15 06:18 +08:00 . filepath.Join is so much work to type
//go:build freebsd || openbsd || netbsd || dragonfly || darwin
// +build freebsd openbsd netbsd dragonfly darwin
package fsnotify
import (
"fmt"
"strings"
"testing"
)
func TestRemoveState(t *testing.T) {
var (
tmp = t.TempDir()
dir = join(tmp, "dir")
file = join(dir, "file")
)
mkdir(t, dir)
touch(t, file)
w := newWatcher(t, tmp)
addWatch(t, w, tmp)
addWatch(t, w, file)
check := func(wantUser, wantTotal int) {
t.Helper()
if len(w.watches) != wantTotal {
var d []string
for k, v := range w.watches {
d = append(d, fmt.Sprintf("%#v = %#v", k, v))
}
t.Errorf("unexpected number of entries in w.watches (have %d, want %d):\n%v",
len(w.watches), wantTotal, strings.Join(d, "\n"))
}
if len(w.paths) != wantTotal {
var d []string
for k, v := range w.paths {
d = append(d, fmt.Sprintf("%#v = %#v", k, v))
}
t.Errorf("unexpected number of entries in w.paths (have %d, want %d):\n%v",
len(w.paths), wantTotal, strings.Join(d, "\n"))
}
if len(w.userWatches) != wantUser {
var d []string
for k, v := range w.userWatches {
d = append(d, fmt.Sprintf("%#v = %#v", k, v))
}
t.Errorf("unexpected number of entries in w.userWatches (have %d, want %d):\n%v",
len(w.userWatches), wantUser, strings.Join(d, "\n"))
}
}
check(2, 3)
if err := w.Remove(file); err != nil {
t.Fatal(err)
}
check(1, 2)
if err := w.Remove(tmp); err != nil {
t.Fatal(err)
}
check(0, 0)
// Don't check these after ever remove since they don't map easily to number
// of files watches. Just make sure they're 0 after everything is removed.
{
want := 0
if len(w.watchesByDir) != want {
var d []string
for k, v := range w.watchesByDir {
d = append(d, fmt.Sprintf("%#v = %#v", k, v))
}
t.Errorf("unexpected number of entries in w.watchesByDir (have %d, want %d):\n%v",
len(w.watchesByDir), want, strings.Join(d, "\n"))
}
if len(w.dirFlags) != want {
var d []string
for k, v := range w.dirFlags {
d = append(d, fmt.Sprintf("%#v = %#v", k, v))
}
t.Errorf("unexpected number of entries in w.dirFlags (have %d, want %d):\n%v",
len(w.dirFlags), want, strings.Join(d, "\n"))
}
if len(w.fileExists) != want {
var d []string
for k, v := range w.fileExists {
d = append(d, fmt.Sprintf("%#v = %#v", k, v))
}
t.Errorf("unexpected number of entries in w.fileExists (have %d, want %d):\n%v",
len(w.fileExists), want, strings.Join(d, "\n"))
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/butnet/fsnotify.git
[email protected]:butnet/fsnotify.git
butnet
fsnotify
fsnotify
main

搜索帮助