Skip to content

Commit

Permalink
test(filesystem): 修正 windows 测试错误
Browse files Browse the repository at this point in the history
打开的文件未关闭,导致 WritableFS.Reset 无法清空目录
  • Loading branch information
caixw committed Mar 30, 2021
1 parent afe6b93 commit 6430a7e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions filesystem/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ func testWritableFS(wfs WritableFS, a *assert.Assertion) {
a.NotError(err).NotNil(file)
data, err := io.ReadAll(file)
a.NotError(err).Empty(data)
a.NotError(file.Close())

// 写入文件,父目录存在,内容不为空
a.NotError(wfs.WriteFile("dir1/file.png", []byte{1, 2, 3}, fs.ModePerm))
file, err = wfs.Open("dir1/file.png")
a.NotError(err).NotNil(file)
data, err = io.ReadAll(file)
a.NotError(err).Equal(data, []byte{1, 2, 3})
a.NotError(file.Close())

// 重置后内容不再存在
a.NotError(wfs.Reset())
Expand All @@ -42,6 +44,7 @@ func testWritableFS(wfs WritableFS, a *assert.Assertion) {
a.NotError(wfs.WriteFile("dir1/file.png", []byte{1, 2, 3}, fs.ModePerm)) // 重新写入
file, err = wfs.Open("dir1/file.png")
a.NotError(err).NotNil(file)
a.NotError(file.Close())

// 无效的 path 参数
_, err = wfs.Open("/dir1/file.png")
Expand Down

0 comments on commit 6430a7e

Please sign in to comment.