summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-10-09 20:50:39 +0700
committerShulhan <ms@kilabit.info>2021-10-09 22:22:03 +0700
commita8a67adddd684307ae187d1697e5a6391ec2ceb7 (patch)
treefd6ef1b02f19014fdae0506d10253b9073891cd2
parente10df13211f57241b53284dbc06f13323b185601 (diff)
downloadpakakeh.go-a8a67adddd684307ae187d1697e5a6391ec2ceb7.tar.xz
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".
-rw-r--r--lib/io/dirwatcher.go1
-rw-r--r--lib/io/dirwatcher_test.go7
2 files changed, 7 insertions, 1 deletions
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
@@ -41,6 +41,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)