-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added common test cases for cache4k (#3501)
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
arrow-libs/core/arrow-cache4k/src/commonTest/kotlin/arrow/core/Cache4kTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package arrow.core | ||
|
||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.time.Duration | ||
|
||
class Cache4kTest { | ||
|
||
@Test fun cacheShouldReturnSavedValueByKeyCorrectly() = runTest { | ||
val cache = Cache4kMemoizationCache<String, Int>(buildCache4K { expireAfterAccess(Duration.INFINITE) }) | ||
val expectedKey = "user:age:userId:5" | ||
val expectedValue = 32 | ||
|
||
cache.set(expectedKey, expectedValue) | ||
cache.get(expectedKey) shouldBe expectedValue | ||
} | ||
|
||
@Test fun cacheShouldReturnNullCauseTryGetByUnsavedKey() = runTest { | ||
val cache = Cache4kMemoizationCache<String, Int>(buildCache4K { expireAfterAccess(Duration.INFINITE) }) | ||
val expectedKey = "user:name:userId:5" | ||
|
||
cache.get(expectedKey) shouldBe null | ||
} | ||
} |