Fix CamelConfigITCase.testCamelListConfig - #26229
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 1 tested, 0 compile-only — current: 0 all testedMaveniverse Scalpel detected 1 affected modules (current approach: 0).
|
gnodet
left a comment
There was a problem hiding this comment.
The intent of this change is good — checking each config line independently to avoid order-sensitivity. However, the implementation has a compilation issue.
checkCommandOutputs(String command, String contains) in JBangTestSupport takes a single String, but this PR passes a String[]. This would fail to compile.
CI didn't catch it because camel-jbang-it has <maven.test.skip>true</maven.test.skip> by default, which skips test compilation entirely.
Two possible fixes:
-
Add an overload to
JBangTestSupport— something like:protected void checkCommandOutputs(String command, String... contains) { String output = execute(command); for (String c : contains) { Assertions.assertThat(output) .as("command " + getMainCommand() + " " + command + " should output " + c) .contains(c); } }
This leverages AssertJ per-line and keeps the order-independent semantics.
-
Use individual calls (simpler, no shared code change):
String output = execute("config list"); assertThat(output).contains("gav = com.foo:acme:1.0-SNAPSHOT"); assertThat(output).contains("runtime = quarkus"); assertThat(output).contains("directory = " + mountPoint());
Option 1 is cleaner since it creates a reusable pattern for other tests that might have the same order-sensitivity problem.
Review generated with AI assistance — please verify before applying.
On behalf of @gnodet
| new String[] { | ||
| "gav = com.foo:acme:1.0-SNAPSHOT", | ||
| "runtime = quarkus", | ||
| "directory = " + mountPoint() }); |
There was a problem hiding this comment.
checkCommandOutputs(String, String) does not have an overload accepting String[]. This code won't compile.
Since the existing checkCommandOutputs only takes a single String, you'll need to either add a varargs overload in JBangTestSupport or check each line individually.
Suggested varargs overload for JBangTestSupport:
protected void checkCommandOutputs(String command, String... contains) {
String output = execute(command);
for (String c : contains) {
Assertions.assertThat(output)
.as("command " + getMainCommand() + " " + command + " should output " + c)
.contains(c);
}
}Note: changing the existing (String, String) signature to (String, String...) is source-compatible — all existing callers pass a single string which matches the varargs.
The order of config in the output is not important, check only if they are all there it avoids this error: ``` [command camel config list should output gav = com.foo:acme:1.0-SNAPSHOT runtime = quarkus directory = /deployments/data/84965e9286b07] Expecting actual: "----- Global ----- gav = com.foo:acme:1.0-SNAPSHOT directory = /deployments/data/84965e9286b07 runtime = quarkus " to contain: "gav = com.foo:acme:1.0-SNAPSHOT runtime = quarkus directory = /deployments/data/84965e9286b07" ``` Signed-off-by: Aurélien Pupier <apupier@ibm.com>
d506fcf to
99e1c26
Compare
gnodet
left a comment
There was a problem hiding this comment.
Thanks for the update — the varargs overload is the right approach and addresses the compilation issue from the first revision.
Two remaining items:
-
testCamelUnsetConfighas the same order-sensitivity bug — it still uses the concatenated string pattern at line 50–53. Since it callscheckCommandOutputs("config list", ...)with the same multi-line expected output, it will be flaky for the same reason. Should be converted to use the new varargs overload too. -
.as()message prints array reference — In the new varargs method,"... should output each of these lines " + containswill print[Ljava.lang.String;@<hash>sincecontainsis aString[]. Usejava.util.Arrays.toString(contains)for a readable message. Also minor: there's a double space in"command "(the existing single-arg version uses one space).
Item 1 is the important one — it defeats the purpose of the PR if the same test class still has the same flaky pattern elsewhere.
Review generated with AI assistance — please verify before applying.
On behalf of @gnodet
|
|
||
| protected void checkCommandOutputs(String command, String... contains) { | ||
| Assertions.assertThat(execute(command)) | ||
| .as("command " + getMainCommand() + " " + command + " should output each of these lines " + contains) |
There was a problem hiding this comment.
Two nits:
+ contains→+ java.util.Arrays.toString(contains)(otherwise this prints[Ljava.lang.String;@hash)- Double space:
"command "→"command "
| .as("command " + getMainCommand() + " " + command + " should output each of these lines " + contains) | |
| protected void checkCommandOutputs(String command, String... contains) { | |
| Assertions.assertThat(execute(command)) | |
| .as("command " + getMainCommand() + " " + command + " should output each of these lines " + java.util.Arrays.toString(contains)) | |
| .contains(contains); | |
| } |
The order of config in the output is not important, check only if they are all there
it avoids this error:
Description
Target
mainbranch)Tracking
Apache Camel coding standards and style
mvn clean install -DskipTestslocally from root folder and I have committed all auto-generated changes.AI-assisted contributions
Co-authored-bytrailers) and the PR description identifies the AI tool used.