Skip to content

Commit

Permalink
Add another minimal test for export json_schema --strict and --minimal
Browse files Browse the repository at this point in the history
Do a rough length comparison
  • Loading branch information
Grifs committed Oct 20, 2023
1 parent 2d28670 commit 6244c95
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/test/scala/io/viash/e2e/export/MainExportSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,47 @@ class MainExportSuite extends AnyFunSuite with BeforeAndAfter {
assert(lines.contains(""""$ref" : "#/definitions/Config""""))
}

test("viash export json_schema --strict and --minimal variants") {
val testOutput = TestHelper.testMain(
"export", "json_schema"
)

val testOutputStrict = TestHelper.testMain(
"export", "json_schema",
"--strict"
)

val testOutputMinimal = TestHelper.testMain(
"export", "json_schema",
"--minimal"
)

val testOutputStrictMinimal = TestHelper.testMain(
"export", "json_schema",
"--strict", "--minimal"
)

assert(testOutput.stdout.startsWith("""$schema: "https://json-schema.org/draft-07/schema#""""))
assert(testOutput.stdout.contains("""- $ref: "#/definitions/Config""""))

assert(testOutputStrict.stdout.startsWith("""$schema: "https://json-schema.org/draft-07/schema#""""))
assert(testOutputStrict.stdout.contains("""- $ref: "#/definitions/Config""""))

assert(testOutputMinimal.stdout.startsWith("""$schema: "https://json-schema.org/draft-07/schema#""""))
assert(testOutputMinimal.stdout.contains("""- $ref: "#/definitions/Config""""))

assert(testOutputStrictMinimal.stdout.startsWith("""$schema: "https://json-schema.org/draft-07/schema#""""))
assert(testOutputStrictMinimal.stdout.contains("""- $ref: "#/definitions/Config""""))

// thresholds were chosen empirically
// at the time of writing:
// testOutput: 125424
// testOutputStrict: 98280
// testOutputMinimal: 30681
// testOutputStrictMinimal: 24191
assert (testOutput.stdout.length * 90 / 100 > testOutputStrict.stdout.length, s"strict output should be at least 10% smaller than default output. ${testOutput.stdout.length} vs ${testOutputStrict.stdout.length}")
assert (testOutput.stdout.length * 40 / 100 > testOutputMinimal.stdout.length, s"minimal output should be at least 60% smaller than default output. ${testOutput.stdout.length} vs ${testOutputMinimal.stdout.length}")
assert (testOutputMinimal.stdout.length * 90 / 100 > testOutputStrictMinimal.stdout.length, s"strict minimal output should be at least 10% smaller than minimal output. ${testOutputMinimal.stdout.length} vs ${testOutputStrictMinimal.stdout.length}")
}

}

0 comments on commit 6244c95

Please sign in to comment.