Commit
This commit is contained in:
parent
7ccf8e041f
commit
086bb9b6e4
10 changed files with 95 additions and 48 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "2.2.21"
|
kotlin("multiplatform") version "2.2.21"
|
||||||
|
kotlin("plugin.serialization") version "2.2.21"
|
||||||
|
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
|
|
@ -24,14 +25,6 @@ kotlin {
|
||||||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
||||||
}
|
}
|
||||||
|
|
||||||
nativeTarget.apply {
|
|
||||||
binaries {
|
|
||||||
executable {
|
|
||||||
entryPoint = "dn42.m724.registry.main"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
nativeMain.dependencies {
|
nativeMain.dependencies {
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-io-core:0.8.0")
|
implementation("org.jetbrains.kotlinx:kotlinx-io-core:0.8.0")
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
package dn42.m724.registry
|
|
||||||
|
|
||||||
import dn42.m724.registry.model.Maintainer
|
|
||||||
|
|
||||||
class FileSystemRegistryLoader(
|
|
||||||
|
|
||||||
) : RegistryLoader {
|
|
||||||
override fun getMaintainer(maintainerName: String): Maintainer {
|
|
||||||
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
package eu.m724.dn42.m724.registry
|
|
||||||
|
|
||||||
import dn42.m724.registry.FileSystemRegistryLoader
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val loader = FileSystemRegistryLoader()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package dn42.m724.registry
|
|
||||||
|
|
||||||
import dn42.m724.registry.model.Maintainer
|
|
||||||
|
|
||||||
interface RegistryLoader {
|
|
||||||
fun getMaintainer(maintainerName: String): Maintainer
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package dn42.m724.registry.loader
|
||||||
|
|
||||||
|
import dn42.m724.registry.serializer.RegistryObjectSerializer
|
||||||
|
import kotlinx.io.buffered
|
||||||
|
import kotlinx.io.files.Path
|
||||||
|
import kotlinx.io.files.SystemFileSystem
|
||||||
|
|
||||||
|
class FileSystemRegistryLoader(
|
||||||
|
val root: Path
|
||||||
|
) : RegistryLoader {
|
||||||
|
override fun getData(path: String): Map<String, List<String>> {
|
||||||
|
check(!path.contains("..")) { "Path may not contain ..s"}
|
||||||
|
|
||||||
|
return SystemFileSystem.source(
|
||||||
|
path = Path(root, "data", path)
|
||||||
|
).buffered().use { source ->
|
||||||
|
RegistryObjectSerializer.readToMap(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package dn42.m724.registry.loader
|
||||||
|
|
||||||
|
interface RegistryLoader {
|
||||||
|
/**
|
||||||
|
* Fetches and processes data from the specified path.
|
||||||
|
*
|
||||||
|
* @param path The relative path within the registry.
|
||||||
|
* @return A map where each key is associated with a list of corresponding values
|
||||||
|
* as defined by the data file at the specified path.
|
||||||
|
*/
|
||||||
|
fun getData(path: String): Map<String, List<String>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches and processes data from the specified path.
|
||||||
|
*
|
||||||
|
* @param path The segments of a relative path within the registry, passed as a variable-length argument.
|
||||||
|
* @return A map where each key is associated with a list of corresponding values
|
||||||
|
* as defined by the data file at the specified path.
|
||||||
|
*/
|
||||||
|
fun getData(vararg path: String): Map<String, List<String>> = getData(path.joinToString("/"))
|
||||||
|
}
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
package dn42.m724.registry.model
|
|
||||||
|
|
||||||
class Maintainer {
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package dn42.m724.registry.loader
|
||||||
|
|
||||||
|
import dn42.m724.registry.test.getResourcePath
|
||||||
|
import dn42.m724.registry.test.shouldContainExactly
|
||||||
|
import kotlinx.io.files.FileNotFoundException
|
||||||
|
import kotlin.test.BeforeTest
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
|
class FileSystemRegistryLoaderTest {
|
||||||
|
lateinit var loader: FileSystemRegistryLoader
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
fun initializeLoader() {
|
||||||
|
loader = FileSystemRegistryLoader(getResourcePath("registry"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getData should return a map for successful parse`() {
|
||||||
|
val map = loader.getData("mntner", "EXAMPLE-MNT")
|
||||||
|
|
||||||
|
map shouldContainExactly mapOf(
|
||||||
|
"mntner" to listOf("EXAMPLE-MNT"),
|
||||||
|
"mnt-by" to listOf("EXAMPLE-MNT"),
|
||||||
|
"auth" to listOf(
|
||||||
|
"pgp-fingerprint 2DE81640E41DD84A9ED9B8F8FD4D7C6652E72E7B",
|
||||||
|
"pgp-fingerprint 139F1460BC66A19A2F880D8D47BA020D8EBCC05E"
|
||||||
|
),
|
||||||
|
"remarks" to listOf(
|
||||||
|
"This has spaces too yay!",
|
||||||
|
"As well as emojis \uD83D\uDE18!",
|
||||||
|
"Also: commas",
|
||||||
|
"" // blank value
|
||||||
|
),
|
||||||
|
"source" to listOf("DN42")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getData should throw FileNotFoundException for not existing file`() {
|
||||||
|
assertFailsWith<FileNotFoundException> {
|
||||||
|
loader.getData("mntner", "NOTEXIST-MNT")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ class RegistryObjectSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `readToMap should throw InvalidKeyException when the key contains illegal numbers`() {
|
fun `readToMap should throw InvalidKeyException when the key contains illegal numbers`() {
|
||||||
withMockSource("li6ne: this has number! not possible have number!") { source ->
|
withMockSource("li6ne: this has number! not possible have number!") { source ->
|
||||||
assertFailsWith(InvalidKeyException::class) {
|
assertFailsWith<InvalidKeyException> {
|
||||||
RegistryObjectSerializer.readToMap(source)
|
RegistryObjectSerializer.readToMap(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,7 @@ class RegistryObjectSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `readToMap should throw InvalidKeyException when a key contains illegal greater than characters`() {
|
fun `readToMap should throw InvalidKeyException when a key contains illegal greater than characters`() {
|
||||||
withMockSource("li>ne: this has >! cannot have !") { source ->
|
withMockSource("li>ne: this has >! cannot have !") { source ->
|
||||||
assertFailsWith(InvalidKeyException::class) {
|
assertFailsWith<InvalidKeyException> {
|
||||||
RegistryObjectSerializer.readToMap(source)
|
RegistryObjectSerializer.readToMap(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,7 @@ class RegistryObjectSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `readToMap should throw InvalidKeyException when a key contains illegal spaces`() {
|
fun `readToMap should throw InvalidKeyException when a key contains illegal spaces`() {
|
||||||
withMockSource(" line: leading ! bad!") { source ->
|
withMockSource(" line: leading ! bad!") { source ->
|
||||||
assertFailsWith(InvalidKeyException::class) {
|
assertFailsWith<InvalidKeyException> {
|
||||||
RegistryObjectSerializer.readToMap(source)
|
RegistryObjectSerializer.readToMap(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ class RegistryObjectSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `readToMap should throw InvalidKeyException when a key contains uppercase characters`() {
|
fun `readToMap should throw InvalidKeyException when a key contains uppercase characters`() {
|
||||||
withMockSource("Line: Content") { source ->
|
withMockSource("Line: Content") { source ->
|
||||||
assertFailsWith(InvalidKeyException::class) {
|
assertFailsWith<InvalidKeyException> {
|
||||||
RegistryObjectSerializer.readToMap(source)
|
RegistryObjectSerializer.readToMap(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ class RegistryObjectSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `readToMap should throw InvalidKeyException when a key is empty`() {
|
fun `readToMap should throw InvalidKeyException when a key is empty`() {
|
||||||
withMockSource(": what key?") { source ->
|
withMockSource(": what key?") { source ->
|
||||||
assertFailsWith(InvalidKeyException::class) {
|
assertFailsWith<InvalidKeyException> {
|
||||||
RegistryObjectSerializer.readToMap(source)
|
RegistryObjectSerializer.readToMap(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ class RegistryObjectSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `readToMap should throw MissingKeyException when there's an invalid pair`() {
|
fun `readToMap should throw MissingKeyException when there's an invalid pair`() {
|
||||||
withMockSource("line: content\nanother line") { source ->
|
withMockSource("line: content\nanother line") { source ->
|
||||||
assertFailsWith(MissingKeyException::class) {
|
assertFailsWith<MissingKeyException> {
|
||||||
RegistryObjectSerializer.readToMap(source)
|
RegistryObjectSerializer.readToMap(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@ import kotlinx.io.readString
|
||||||
import kotlinx.io.writeString
|
import kotlinx.io.writeString
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.fail
|
|
||||||
|
|
||||||
private const val RESOURCES_PATH_PREFIX = "src/nativeTest/resources/"
|
private val RESOURCE_ROOT_PATH = Path("src/nativeTest/resources/")
|
||||||
|
|
||||||
fun getResourcePath(resource: String): Path =
|
fun getResourcePath(resource: String): Path =
|
||||||
Path(RESOURCES_PATH_PREFIX + resource)
|
Path(RESOURCE_ROOT_PATH, resource)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a raw source for the specified resource.
|
* Retrieves a raw source for the specified resource.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue