Skip to content

Commit

Permalink
Increase verbosity of testExtensionSchemaValidation tests (#1010)
Browse files Browse the repository at this point in the history
When testExtensionSchemaValidation tests fail, the reason behind those failures are not logged. This replaces `Assert` with `SoftAssert` to always output the reason for failure in the unit tests.
  • Loading branch information
SpencerKwok authored Jul 23, 2024
1 parent b49908d commit eaef65f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and what APIs have changed, if applicable.

## [Unreleased]

## [29.58.1] - 2024-07-19
- Increase verbosity of testExtensionSchemaValidation tests

## [29.58.0] - 2024-07-11
- Allow both @extension and @grpcExtension extensions in schema validation

Expand Down Expand Up @@ -5710,7 +5713,8 @@ patch operations can re-use these classes for generating patch messages.

## [0.14.1]

[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.58.0...master
[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.58.1...master
[29.58.1]: https://github.com/linkedin/rest.li/compare/v29.58.0...v29.58.1
[29.58.0]: https://github.com/linkedin/rest.li/compare/v29.57.2...v29.58.0
[29.57.2]: https://github.com/linkedin/rest.li/compare/v29.57.1...v29.57.2
[29.57.1]: https://github.com/linkedin/rest.li/compare/v29.57.0...v29.57.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.TaskAction;
import org.gradle.process.ExecResult;

import static com.linkedin.pegasus.gradle.SharedFileUtils.*;

Expand Down Expand Up @@ -154,7 +155,7 @@ public void validateExtensionSchema() throws IOException

ByteArrayOutputStream validationOutput = new ByteArrayOutputStream();

getProject().javaexec(javaExecSpec -> {
ExecResult result = getProject().javaexec(javaExecSpec -> {
String resolverPathArg = resolverPathStr;
if (isEnableArgFile())
{
Expand All @@ -167,8 +168,15 @@ public void validateExtensionSchema() throws IOException
javaExecSpec.args(_inputDir.getAbsolutePath());
javaExecSpec.setStandardOutput(validationOutput);
javaExecSpec.setErrorOutput(validationOutput);

// Handle failure after exec to output error to build log
javaExecSpec.setIgnoreExitValue(true);
});

IOUtil.writeText(getOutputFile(), validationOutput.toString(StandardCharsets.UTF_8.name()));
String validationOutputString = validationOutput.toString(StandardCharsets.UTF_8.name());
IOUtil.writeText(getOutputFile(), validationOutputString);
if (result.getExitValue() != 0) {
throw new GradleException("Error occurred during schema extension validation:\n" + validationOutputString);
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=29.58.0
version=29.58.1
group=com.linkedin.pegasus
org.gradle.configureondemand=true
org.gradle.parallel=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.io.File;

import org.testng.Assert;
import org.testng.asserts.SoftAssert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -86,15 +86,19 @@ public void testExtensionSchemaValidation(String inputDir, boolean isValid, Stri
{
String resolverPath = testPegasusDir;
String inputPath = testExtensionDir + File.separator + inputDir;

SoftAssert softAssert = new SoftAssert();
try
{
ExtensionSchemaValidationCmdLineApp.parseAndValidateExtensionSchemas(resolverPath, new File(inputPath));
Assert.assertTrue(isValid);
softAssert.assertTrue(isValid);
softAssert.assertEquals(null, errorMessage);
}
catch (Exception e)
{
Assert.assertTrue(!isValid);
Assert.assertEquals(e.getMessage(), errorMessage);
softAssert.assertTrue(!isValid);
softAssert.assertEquals(e.getMessage(), errorMessage);
}
softAssert.assertAll();
}
}

0 comments on commit eaef65f

Please sign in to comment.