From 1f3cb6197b7275a1c2cab1a7544faba265f7d6dd Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 10 Aug 2022 18:11:10 +0200 Subject: [PATCH] Add test to see what happens if you watch a symlink --- fsnotify_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fsnotify_test.go b/fsnotify_test.go index 993864e4..48ecb010 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -152,6 +152,44 @@ func TestWatch(t *testing.T) { }, ` write /file `}, + + {"watch a symlink to a file", func(t *testing.T, w *Watcher, tmp string) { + file := filepath.Join(tmp, "file") + link := filepath.Join(tmp, "link") + touch(t, file) + symlink(t, file, link) + addWatch(t, w, link) + + cat(t, "hello", file) + }, ` + write /link + + # TODO: Symlinks followed on kqueue; it shouldn't do this, but I'm + # afraid changing it will break stuff. See #227, #390 + kqueue: + write /file + + # TODO: see if we can fix this. + windows: + empty + `}, + + {"watch a symlink to a dir", func(t *testing.T, w *Watcher, tmp string) { + dir := filepath.Join(tmp, "dir") + link := filepath.Join(tmp, "link") + mkdir(t, dir) + symlink(t, dir, link) + addWatch(t, w, link) + + touch(t, dir, "file") + }, ` + create /link/file + + # TODO: Symlinks followed on kqueue; it shouldn't do this, but I'm + # afraid changing it will break stuff. See #227, #390 + kqueue: + create /dir/file + `}, } for _, tt := range tests {