Skip to content

Commit 562787f

Browse files
authored
test: properly close directory handle (#271)
1 parent 739e0b8 commit 562787f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/jsTest/kotlin/it/krzeminski/githubactionstyping/AjvSchemaValidationTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.kotest.matchers.should
1313
import io.kotest.matchers.shouldNot
1414
import io.kotest.mpp.env
1515
import node.buffer.BufferEncoding.Companion.utf8
16+
import node.fs.Dir
1617
import node.fs.exists
1718
import node.fs.existsSync
1819
import node.fs.opendir
@@ -38,7 +39,7 @@ class AjvSchemaValidationTest : FunSpec({
3839
withClue("catalogDir should be a non-empty directory") {
3940
exists(catalogDir).shouldBeTrue()
4041
stat(catalogDir).isDirectory().shouldBeTrue()
41-
opendir(catalogDir).read().await().shouldNotBeNull()
42+
opendir(catalogDir).use { it.read().await().shouldNotBeNull() }
4243
}
4344

4445
validate = Ajv(AjvOptions(strict = true)).compile(
@@ -98,3 +99,7 @@ private suspend fun String.shouldNotBeValid(): String {
9899
readFile(path.join(badDir, this), utf8) shouldNot beValid()
99100
return this
100101
}
102+
103+
private inline fun <R> Dir.use(block: (Dir) -> R): R =
104+
AutoCloseable { closeSync() }
105+
.use { block(this) }

0 commit comments

Comments
 (0)