Skip to content

Commit 70f145f

Browse files
ilgonmicdkrasnoff
authored andcommitted
Add test of resources server
1 parent 192a43f commit 70f145f

File tree

2 files changed

+94
-21
lines changed

2 files changed

+94
-21
lines changed

resource-server/build.gradle.kts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,9 @@ val kotlinComposeWasmStdlib: Configuration by configurations.creating {
5353

5454
dependencies {
5555
implementation("org.springframework.boot:spring-boot-starter-web")
56-
// implementation(libs.springfox.boot.starter)
57-
// implementation(libs.aws.springboot.container)
58-
// implementation(libs.junit)
59-
// implementation(libs.logback.logstash.encoder)
60-
// implementation(libs.intellij.trove4j)
61-
// implementation(libs.kotlin.reflect)
62-
// implementation(libs.bundles.kotlin.stdlib)
63-
// implementation(libs.kotlin.test)
64-
// implementation(libs.kotlin.compiler)
65-
// implementation(libs.kotlin.script.runtime)
66-
// implementation(libs.kotlin.compiler.ide) {
67-
// isTransitive = false
68-
// }
69-
// implementation(libs.kotlin.core)
70-
// implementation(project(":executors", configuration = "default"))
71-
// implementation(project(":common", configuration = "default"))
72-
//
73-
// testImplementation("org.springframework.boot:spring-boot-starter-test") {
74-
// exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
75-
// }
76-
// testImplementation(libs.kotlinx.coroutines.test)
56+
testImplementation("org.springframework.boot:spring-boot-starter-test") {
57+
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
58+
}
7759

7860
resourceDependency(libs.skiko.js.wasm.runtime)
7961
kotlinComposeWasmStdlib(project(":cache-maker"))
@@ -112,4 +94,12 @@ tasks.named<Copy>("processResources") {
11294
from(kotlinComposeWasmStdlib) {
11395
into("com/compiler/server")
11496
}
97+
}
98+
99+
tasks.withType<Test> {
100+
useJUnitPlatform()
101+
javaLauncher.set(javaToolchains.launcherFor {
102+
languageVersion.set(JavaLanguageVersion.of(17))
103+
vendor.set(JvmVendorSpec.AMAZON)
104+
})
115105
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.compiler.server
2+
3+
import org.junit.jupiter.api.Test
4+
import org.springframework.beans.factory.annotation.Autowired
5+
import org.springframework.beans.factory.annotation.Value
6+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
7+
import org.springframework.boot.test.context.SpringBootTest
8+
import org.springframework.http.HttpHeaders
9+
import org.springframework.test.web.servlet.MockMvc
10+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
11+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
12+
import java.util.concurrent.TimeUnit
13+
14+
@SpringBootTest
15+
@AutoConfigureMockMvc
16+
class SkikoResourceTest {
17+
@Autowired
18+
private lateinit var mockMvc: MockMvc
19+
20+
@Value("\${skiko.version}")
21+
private lateinit var skikoVersion: String
22+
23+
@Value("\${dependencies.compose.wasm}")
24+
private lateinit var stdlibHash: String
25+
26+
@Test
27+
fun `test caching headers for skiko mjs resource`() {
28+
testCachingHeadersForResource(
29+
"/api/resource/skiko-$skikoVersion.mjs",
30+
"text/javascript"
31+
)
32+
}
33+
34+
@Test
35+
fun `test caching headers for skiko wasm resource`() {
36+
testCachingHeadersForResource(
37+
"/api/resource/skiko-$skikoVersion.wasm",
38+
"application/wasm"
39+
)
40+
}
41+
42+
@Test
43+
fun `test caching headers for stdlib mjs resource`() {
44+
testCachingHeadersForResource(
45+
"/api/resource/stdlib-$stdlibHash.mjs",
46+
"text/javascript"
47+
)
48+
}
49+
50+
@Test
51+
fun `test caching headers for stdlib wasm resource`() {
52+
testCachingHeadersForResource(
53+
"/api/resource/stdlib-$stdlibHash.wasm",
54+
"application/wasm"
55+
)
56+
}
57+
58+
private fun testCachingHeadersForResource(
59+
resourceUrl: String,
60+
contentType: String
61+
) {
62+
val expectedCacheControl = "max-age=${TimeUnit.DAYS.toSeconds(365)}"
63+
64+
mockMvc
65+
.perform(MockMvcRequestBuilders.get(resourceUrl))
66+
.andExpect(MockMvcResultMatchers.status().isOk) // HTTP 200 status
67+
.andExpect(
68+
MockMvcResultMatchers.header().exists(HttpHeaders.CACHE_CONTROL)
69+
)
70+
.andExpect(
71+
MockMvcResultMatchers.header().string(
72+
HttpHeaders.CACHE_CONTROL,
73+
expectedCacheControl
74+
)
75+
)
76+
.andExpect(
77+
MockMvcResultMatchers.header().string(
78+
HttpHeaders.CONTENT_TYPE,
79+
contentType
80+
)
81+
)
82+
}
83+
}

0 commit comments

Comments
 (0)