Skip to content

Commit 4ab8a92

Browse files
committed
test(spdx): Make the schema validation more strict
The previously used schema validation of kotest lacks support for a couple of features, such as enums, see [1]. The validation would not flag issues with wrong values for the category of external references, for example `PACKAGE_MANAGER` vs. `PACKAGE-MANAGER`. Make use of `matchJsonSchema()` to also cover enum checks with the assertion. [1]: https://github.com/networknt/json-schema-validator/blob/master/README.md Signed-off-by: Frank Viernau <[email protected]>
1 parent c233f15 commit 4ab8a92

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

plugins/reporters/spdx/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ dependencies {
3939
implementation(libs.jackson.databind)
4040

4141
funTestImplementation(testFixtures(projects.plugins.reporters.spdxReporter))
42-
funTestImplementation(libs.kotest.assertions.json)
4342

4443
testFixturesImplementation(projects.utils.testUtils)
4544
}

plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.ossreviewtoolkit.plugins.reporters.spdx
2121

22-
import io.kotest.assertions.json.schema.parseSchema
23-
import io.kotest.assertions.json.schema.shouldMatchSchema
2422
import io.kotest.common.ExperimentalKotest
2523
import io.kotest.core.TestConfiguration
2624
import io.kotest.core.spec.style.WordSpec
@@ -38,6 +36,7 @@ import org.ossreviewtoolkit.utils.spdxdocument.SpdxModelMapper.FileFormat
3836
import org.ossreviewtoolkit.utils.spdxdocument.SpdxModelMapper.fromJson
3937
import org.ossreviewtoolkit.utils.spdxdocument.SpdxModelMapper.fromYaml
4038
import org.ossreviewtoolkit.utils.spdxdocument.model.SpdxDocument
39+
import org.ossreviewtoolkit.utils.test.matchJsonSchema
4140
import org.ossreviewtoolkit.utils.test.patchExpectedResult
4241
import org.ossreviewtoolkit.utils.test.readOrtResult
4342
import org.ossreviewtoolkit.utils.test.readResource
@@ -46,11 +45,11 @@ class SpdxDocumentReporterFunTest : WordSpec({
4645
"Reporting to JSON" should {
4746
@OptIn(ExperimentalKotest::class)
4847
"create a valid document" {
49-
val schema = parseSchema(readResource("/spdx-v2.2.2-schema.json"))
48+
val schemaJson = readResource("/spdx-v2.2.2-schema.json")
5049

5150
val jsonSpdxDocument = generateReport(ORT_RESULT, FileFormat.JSON)
5251

53-
jsonSpdxDocument shouldMatchSchema schema
52+
jsonSpdxDocument should matchJsonSchema(schemaJson)
5453
}
5554

5655
"create the expected document for a synthetic scan result" {

0 commit comments

Comments
 (0)