[Build, IGS] Ignore non-existing keys during setup file parsing
#KTI-1223 In Progress
This commit is contained in:
committed by
Space Team
parent
ea38cfebf2
commit
cf03863b65
@@ -18,6 +18,10 @@ internal data class SetupFile(
|
|||||||
val properties: Map<String, String>,
|
val properties: Map<String, String>,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val json = Json { ignoreUnknownKeys = true }
|
||||||
|
|
||||||
// can't use decodeFromStream: https://github.com/Kotlin/kotlinx.serialization/issues/2218
|
// can't use decodeFromStream: https://github.com/Kotlin/kotlinx.serialization/issues/2218
|
||||||
internal fun parseSetupFile(inputStream: InputStream): SetupFile =
|
internal fun parseSetupFile(inputStream: InputStream): SetupFile =
|
||||||
Json.decodeFromString(BufferedReader(InputStreamReader(inputStream)).lines().asSequence().joinToString("\n"))
|
json.decodeFromString(
|
||||||
|
BufferedReader(InputStreamReader(inputStream)).lines().asSequence().joinToString("\n")
|
||||||
|
)
|
||||||
+19
-7
@@ -8,15 +8,11 @@ package org.jetbrains.kotlin.build
|
|||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class SetupFileParseTest {
|
class SetupFileParseTest {
|
||||||
private fun openPropertiesJsonStream() =
|
private fun openPropertiesJsonStream(name: String) =
|
||||||
SetupFileParseTest::class.java.classLoader.getResourceAsStream("properties.json")
|
SetupFileParseTest::class.java.classLoader.getResourceAsStream("$name.json")
|
||||||
?: error("No properties.json file found in test resources")
|
?: error("No properties.json file found in test resources")
|
||||||
|
|
||||||
@Test
|
private fun assertSampleSetupFileIsParsedCorrectly(setupFile: SetupFile) {
|
||||||
fun testSimpleParsing() {
|
|
||||||
val setupFile = openPropertiesJsonStream().use {
|
|
||||||
parseSetupFile(it)
|
|
||||||
}
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
mapOf(
|
mapOf(
|
||||||
"newProperty1" to "someValue",
|
"newProperty1" to "someValue",
|
||||||
@@ -26,4 +22,20 @@ class SetupFileParseTest {
|
|||||||
setupFile.properties
|
setupFile.properties
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSimpleParsing() {
|
||||||
|
val setupFile = openPropertiesJsonStream("properties").use {
|
||||||
|
parseSetupFile(it)
|
||||||
|
}
|
||||||
|
assertSampleSetupFileIsParsedCorrectly(setupFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUnknownFieldsDoNotBreakParsing() {
|
||||||
|
val setupFile = openPropertiesJsonStream("properties-with-unknown-fields").use {
|
||||||
|
parseSetupFile(it)
|
||||||
|
}
|
||||||
|
assertSampleSetupFileIsParsedCorrectly(setupFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"newProperty1": "someValue",
|
||||||
|
"newProperty2": "someOtherValue",
|
||||||
|
"alreadySetProperty": "newValue"
|
||||||
|
},
|
||||||
|
"unknownField": "someValue"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user