Skip to content

Commit 9994f0a

Browse files
committed
wip extra test
1 parent 455c56c commit 9994f0a

1 file changed

Lines changed: 77 additions & 1 deletion

File tree

src/test/scala/io/viash/TestingAllComponentsSuite.scala

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package io.viash
22

33
import io.viash.config.Config
44
import org.scalatest.funsuite.AnyFunSuite
5-
import io.viash.helpers.Logger
5+
import io.viash.helpers.{Logger, Exec, IO}
66
import org.scalatest.ParallelTestExecution
77
import io.viash.lenses.ConfigLenses
88
import io.viash.config.{decodeConfig, encodeConfig}
9+
import java.nio.file.{Files, Paths}
10+
import io.circe.parser._
911

1012
class TestingAllComponentsSuite extends AnyFunSuite with ParallelTestExecution {
1113
Logger.UseColorOverride.value = Some(false)
@@ -90,5 +92,79 @@ class TestingAllComponentsSuite extends AnyFunSuite with ParallelTestExecution {
9092
// check if equal
9193
assert(strippedConf2 == conf2)
9294
}
95+
96+
// Test that VIASH_KEEP_WORK_DIR preserves the work directory and params.json is valid
97+
// Skip executable type as it doesn't have a script/language
98+
if (name != "executable") {
99+
test(s"Testing $name params.json generation with VIASH_KEEP_WORK_DIR", DockerTest) {
100+
val tempDir = IO.makeTemp("viash_test_json_")
101+
val executable = tempDir.resolve(s"test_languages_$name")
102+
103+
try {
104+
// Build the component with docker engine
105+
TestHelper.testMain("build", "--engine", "docker", "-o", tempDir.toString, config)
106+
107+
// Run with VIASH_KEEP_WORK_DIR set
108+
val result = Exec.runCatchPath(
109+
List(
110+
executable.toString,
111+
getClass.getResource("/testbash/resource1.txt").getPath,
112+
"--whole_number", "42",
113+
"--real_number", "3.14",
114+
"-s", "test_string",
115+
"--multiple", "a", "--multiple", "b"
116+
),
117+
cwd = None,
118+
extraEnv = Seq("VIASH_KEEP_WORK_DIR" -> "1")
119+
)
120+
121+
assert(result.exitValue == 0, s"Component execution failed:\n${result.output}")
122+
123+
// Extract work directory path from output
124+
val workDirPattern = """Keeping work directory at '([^']+)'""".r
125+
val workDirMatch = workDirPattern.findFirstMatchIn(result.output)
126+
assert(workDirMatch.isDefined, s"Could not find work directory path in output:\n${result.output}")
127+
128+
val workDir = Paths.get(workDirMatch.get.group(1))
129+
val paramsJson = workDir.resolve("params.json")
130+
131+
// Verify params.json exists
132+
assert(Files.exists(paramsJson), s"params.json not found at $paramsJson")
133+
134+
// Read and parse JSON
135+
val jsonContent = new String(Files.readAllBytes(paramsJson))
136+
val json = parse(jsonContent)
137+
assert(json.isRight, s"Invalid JSON:\n$jsonContent")
138+
139+
// Verify JSON structure
140+
val jsonObj = json.toOption.get.asObject.get
141+
assert(jsonObj.contains("par"), "JSON should contain 'par' section")
142+
assert(jsonObj.contains("meta"), "JSON should contain 'meta' section")
143+
assert(jsonObj.contains("dep"), "JSON should contain 'dep' section")
144+
145+
// Verify par section has expected values
146+
val par = jsonObj("par").get.asObject.get
147+
assert(par("whole_number").get.asNumber.get.toInt.contains(42), "whole_number should be 42")
148+
val realNum = par("real_number").get.asNumber.get.toDouble
149+
assert(math.abs(realNum - 3.14) < 0.001, s"real_number should be 3.14, got $realNum")
150+
assert(par("s").get.asString.contains("test_string"), "s should be 'test_string'")
151+
152+
// Verify array parameter
153+
val multiple = par("multiple").get.asArray.get
154+
assert(multiple.length == 2, "multiple should have 2 elements")
155+
assert(multiple(0).asString.contains("a"), "first element should be 'a'")
156+
assert(multiple(1).asString.contains("b"), "second element should be 'b'")
157+
158+
// Verify meta section
159+
val meta = jsonObj("meta").get.asObject.get
160+
assert(meta("name").get.asString.contains(s"test_languages_$name"), s"name should be test_languages_$name")
161+
162+
// Clean up work directory
163+
IO.deleteRecursively(workDir)
164+
} finally {
165+
IO.deleteRecursively(tempDir)
166+
}
167+
}
168+
}
93169
}
94170
}

0 commit comments

Comments
 (0)