Skip to content

Commit

Permalink
Add test of resources server
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic committed Jan 21, 2025
1 parent e35603b commit 13f2848
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 21 deletions.
32 changes: 11 additions & 21 deletions resource-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -112,4 +94,12 @@ tasks.named<Copy>("processResources") {
from(kotlinComposeWasmStdlib) {
into("com/compiler/server")
}
}

tasks.withType<Test> {
useJUnitPlatform()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.AMAZON)
})
}
Original file line number Diff line number Diff line change
@@ -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
)
)
}
}

0 comments on commit 13f2848

Please sign in to comment.