Skip to content
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
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[versions]
burst = "2.10.2"
changelog = "2.4.0"
clikt = "5.0.3"
intellij-platform = "2.10.2"
Expand All @@ -25,6 +26,7 @@ oshai-logging = { module = "io.github.oshai:kotlin-logging-jvm", version.ref = "
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }

[plugins]
burst = { id = "app.cash.burst", version.ref = "burst" }
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
intellij-platform = { id = "org.jetbrains.intellij.platform", version.ref = "intellij-platform" }
1 change: 1 addition & 0 deletions scripting-host/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.gradle.jvm.component.internal.JvmSoftwareComponentInternal

plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.burst)
application
}

Expand Down
57 changes: 0 additions & 57 deletions scripting-host/src/test/kotlin/ServerScriptingHostCacheTest.kt

This file was deleted.

59 changes: 0 additions & 59 deletions scripting-host/src/test/kotlin/ServerScriptingHostScriptsTest.kt

This file was deleted.

75 changes: 75 additions & 0 deletions scripting-host/src/test/kotlin/ServerScriptingHostTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2024 Eduard Wolf
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.edwardday.serverscript.scripthost

import app.cash.burst.Burst
import kotlinx.coroutines.test.runTest
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals


@Burst
class ServerScriptingHostTest {

@Test
fun testScript(
testCase: TestCases.Script,
) = runTest {
val testData = readResource(testCase.fileName)

val actual = executeWithUnixDomainSockets { executeScript(it, testData) }

assertEquals(testData.body, actual)
}

@Test
fun testCacheScript(
testCase: TestCases.CacheScript,
) = runTest {
val urls = testCase.fileNames.map { readResource(it) }
val expected = when (testCase) {
TestCases.CacheScript.CACHE_DATA -> {
urls.mapIndexed { index, testData -> testData.body.map { it.replace("{counter}", "${index + 1}") } }
}

TestCases.CacheScript.CACHE_IMPORT_SCRIPT -> {
urls.map(TestData::body)
}
}

val actualResponses = executeWithUnixDomainSockets {
executeScripts(it, urls)
}

assertEquals(expected, actualResponses)
}

@Test
fun checkAllTestcasesCovered() {
val path = Thread.currentThread().contextClassLoader.getResource("imports")!!.path
val expected = File(path).parentFile.listFiles { _, name -> name.endsWith(".server.kts") }
.orEmpty()
.map { it.name.removeSuffix(".server.kts") }
.toSet()

val actual =
(TestCases.Script.entries + TestCases.CacheScript.entries).flatMapTo(mutableSetOf(), TestCases::fileNames)

assertEquals(expected, actual)
}
}
32 changes: 32 additions & 0 deletions scripting-host/src/test/kotlin/TestCases.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.edwardday.serverscript.scripthost

interface TestCases {
val fileNames: List<String>

enum class Script(val fileName: String) : TestCases {
BIG_OUTPUT("big_output"),
CUSTOM_HEADERS("custom_headers"),
DEPENDENCY("dependency"),
DEPENDENCY_REPOSITORY("dependency_repository"),
EMPTY("empty"),
EXCEPTION("exception"),
IMPORT_FUNCTION("import_function"),
IMPORT_INVALID("import_invalid"),
IMPORT_NOT_EXISTENT("import_not_existent"),
IMPORT_SCRIPT("import_script"),
INVALID("invalid"),
KNOWN_STATUS("known_status"),
MULTIPLE_OUTPUT("multiple_output"),
SIMPLE_SCRIPT("simple_script"),
UNKNOWN_STATUS("unknown_status"),
;

override val fileNames: List<String> get() = listOf(fileName)
}

enum class CacheScript(override val fileNames: List<String>) : TestCases {
CACHE_DATA(List(5) { "cache_data" }),
CACHE_IMPORT_SCRIPT(listOf("cache_import_script_1", "cache_import_script_2")),
;
}
}