Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added common basic test cases for cache4k #3501

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion arrow-libs/core/arrow-cache4k/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


plugins {
Expand All @@ -15,7 +16,7 @@ apply(from = property("ANIMALSNIFFER_MPP"))

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion.set(JavaLanguageVersion.of(17))
}
}

Expand All @@ -29,6 +30,13 @@ kotlin {
api(libs.cache4k)
}
}
commonTest {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotest.assertionsCore)
implementation(libs.coroutines.test)
}
}
}

jvm {
Expand Down Expand Up @@ -75,3 +83,8 @@ tasks.named<Jar>("jvmJar").configure {
attributes["Automatic-Module-Name"] = "arrow.cache4k"
}
}

// enables context receivers for Jvm Tests
tasks.named<KotlinCompile>("compileTestKotlinJvm") {
compilerOptions.freeCompilerArgs.add("-Xcontext-receivers")
}
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
}
}