From a8a67adddd684307ae187d1697e5a6391ec2ceb7 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 9 Oct 2021 20:50:39 +0700 Subject: lib/io: fix test on DirWatcher On the test we re-create the root directory with sub-directory. This action will trigger two FileStateCreated events, one for root "/" and another one for sub-directory "/assets". --- lib/io/dirwatcher.go | 1 + lib/io/dirwatcher_test.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/io/dirwatcher.go b/lib/io/dirwatcher.go index 994f44af..857fde89 100644 --- a/lib/io/dirwatcher.go +++ b/lib/io/dirwatcher.go @@ -333,6 +333,7 @@ func (dw *DirWatcher) start() { } if dw.fs == nil { dw.onRootCreated() + dw.onContentChange(dw.root) continue } if dw.root.Mode() != newDirInfo.Mode() { diff --git a/lib/io/dirwatcher_test.go b/lib/io/dirwatcher_test.go index 95839a98..9df6dcec 100644 --- a/lib/io/dirwatcher_test.go +++ b/lib/io/dirwatcher_test.go @@ -40,6 +40,9 @@ func TestDirWatcher(t *testing.T) { }, { state: FileStateCreated, path: "/", + }, { + state: FileStateCreated, + path: "/assets", }, { state: FileStateUpdateMode, path: "/", @@ -108,9 +111,11 @@ func TestDirWatcher(t *testing.T) { wg.Wait() // Create the watched directory back with sub directory + // This will trigger two FileStateCreated events, one for "/" and one + // for "/assets". dirAssets := filepath.Join(dir, "assets") t.Logf("Re-create root directory %q ...\n", dirAssets) - wg.Add(1) + wg.Add(2) err = os.MkdirAll(dirAssets, 0770) if err != nil { t.Fatal(err) -- cgit v1.3