From 13f28482a0c5e1969af282935633efc06e4e4031 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Tue, 21 Jan 2025 19:20:02 +0100 Subject: [PATCH] Add test of resources server --- resource-server/build.gradle.kts | 32 +++---- .../com/compiler/server/SkikoResourceTest.kt | 83 +++++++++++++++++++ 2 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 resource-server/src/test/kotlin/com/compiler/server/SkikoResourceTest.kt diff --git a/resource-server/build.gradle.kts b/resource-server/build.gradle.kts index d30f2cc3..aab551fe 100644 --- a/resource-server/build.gradle.kts +++ b/resource-server/build.gradle.kts @@ -53,27 +53,9 @@ val kotlinComposeWasmStdlib: Configuration by configurations.creating { dependencies { implementation("org.springframework.boot:spring-boot-starter-web") -// implementation(libs.springfox.boot.starter) -// implementation(libs.aws.springboot.container) -// implementation(libs.junit) -// implementation(libs.logback.logstash.encoder) -// implementation(libs.intellij.trove4j) -// implementation(libs.kotlin.reflect) -// implementation(libs.bundles.kotlin.stdlib) -// implementation(libs.kotlin.test) -// implementation(libs.kotlin.compiler) -// implementation(libs.kotlin.script.runtime) -// implementation(libs.kotlin.compiler.ide) { -// isTransitive = false -// } -// implementation(libs.kotlin.core) -// implementation(project(":executors", configuration = "default")) -// implementation(project(":common", configuration = "default")) -// -// testImplementation("org.springframework.boot:spring-boot-starter-test") { -// exclude(group = "org.junit.vintage", module = "junit-vintage-engine") -// } -// testImplementation(libs.kotlinx.coroutines.test) + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(group = "org.junit.vintage", module = "junit-vintage-engine") + } resourceDependency(libs.skiko.js.wasm.runtime) kotlinComposeWasmStdlib(project(":cache-maker")) @@ -112,4 +94,12 @@ tasks.named("processResources") { from(kotlinComposeWasmStdlib) { into("com/compiler/server") } +} + +tasks.withType { + useJUnitPlatform() + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(17)) + vendor.set(JvmVendorSpec.AMAZON) + }) } \ No newline at end of file diff --git a/resource-server/src/test/kotlin/com/compiler/server/SkikoResourceTest.kt b/resource-server/src/test/kotlin/com/compiler/server/SkikoResourceTest.kt new file mode 100644 index 00000000..cde6a5e7 --- /dev/null +++ b/resource-server/src/test/kotlin/com/compiler/server/SkikoResourceTest.kt @@ -0,0 +1,83 @@ +package com.compiler.server + +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.HttpHeaders +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders +import org.springframework.test.web.servlet.result.MockMvcResultMatchers +import java.util.concurrent.TimeUnit + +@SpringBootTest +@AutoConfigureMockMvc +class SkikoResourceTest { + @Autowired + private lateinit var mockMvc: MockMvc + + @Value("\${skiko.version}") + private lateinit var skikoVersion: String + + @Value("\${dependencies.compose.wasm}") + private lateinit var stdlibHash: String + + @Test + fun `test caching headers for skiko mjs resource`() { + testCachingHeadersForResource( + "/api/resource/skiko-$skikoVersion.mjs", + "text/javascript" + ) + } + + @Test + fun `test caching headers for skiko wasm resource`() { + testCachingHeadersForResource( + "/api/resource/skiko-$skikoVersion.wasm", + "application/wasm" + ) + } + + @Test + fun `test caching headers for stdlib mjs resource`() { + testCachingHeadersForResource( + "/api/resource/stdlib-$stdlibHash.mjs", + "text/javascript" + ) + } + + @Test + fun `test caching headers for stdlib wasm resource`() { + testCachingHeadersForResource( + "/api/resource/stdlib-$stdlibHash.wasm", + "application/wasm" + ) + } + + private fun testCachingHeadersForResource( + resourceUrl: String, + contentType: String + ) { + val expectedCacheControl = "max-age=${TimeUnit.DAYS.toSeconds(365)}" + + mockMvc + .perform(MockMvcRequestBuilders.get(resourceUrl)) + .andExpect(MockMvcResultMatchers.status().isOk) // HTTP 200 status + .andExpect( + MockMvcResultMatchers.header().exists(HttpHeaders.CACHE_CONTROL) + ) + .andExpect( + MockMvcResultMatchers.header().string( + HttpHeaders.CACHE_CONTROL, + expectedCacheControl + ) + ) + .andExpect( + MockMvcResultMatchers.header().string( + HttpHeaders.CONTENT_TYPE, + contentType + ) + ) + } +} \ No newline at end of file