Skip to content

Commit

Permalink
Fix SBOM integration test bug and clarify test intent
Browse files Browse the repository at this point in the history
  • Loading branch information
rudsberg authored and dnestoro committed Jan 13, 2025
1 parent 92917b0 commit bee5ead
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SBOMFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
}

@Requires({ supportedAugmentedSBOMVersion() })
def "sbom is created when buildArg '--enable-sbom=export,embed' is used"() {
def "sbom is exported and embedded when buildArg '--enable-sbom=export,embed' is used"() {
withSample 'java-application'

when:
Expand All @@ -82,29 +82,26 @@ class SBOMFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
buildSucceeded
outputContainsPattern".*CycloneDX SBOM with \\d+ component\\(s\\) is embedded in binary \\(.*?\\) and exported as JSON \\(see build artifacts\\)\\."
outputDoesNotContain "Use '--enable-sbom' to assemble a Software Bill of Materials (SBOM)"
validateSbom sbom
validateExportedSBOM sbom
!file(String.format("target/%s", SBOMGenerator.SBOM_FILENAME)).exists()
outputContains "Hello, native!"
}

/**
* If user sets {@link NativeCompileNoForkMojo#AUGMENTED_SBOM_PARAM_NAME} to true then an SBOM should be generated
* with default SBOM arguments even if user did not explicitly specify '--enable-sbom' as a buildArg.
* If user sets {@link NativeCompileNoForkMojo#AUGMENTED_SBOM_PARAM_NAME} to true then Native Image should be
* invoked with '--enable-sbom' and an SBOM should be embedded in the image.
*/
@Requires({ supportedAugmentedSBOMVersion() })
def "sbom is created when only the augmented sbom parameter is used (but not the '--enable-sbom' buildArg)"() {
def "sbom is embedded when only the augmented sbom parameter is used (but not the '--enable-sbom' buildArg)"() {
withSample 'java-application'
when:
mvn '-Pnative-augmentedSBOM-only', '-DquickBuild', '-DskipTests', 'package', 'exec:exec@native'
def sbom = file("target/example-app.sbom.json")
then:
buildSucceeded
outputContainsPattern".*CycloneDX SBOM with \\d+ component\\(s\\) is embedded in binary \\(.*?\\)."
outputDoesNotContain "Use '--enable-sbom' to assemble a Software Bill of Materials (SBOM)"
validateSbom sbom
!file(String.format("target/%s", SBOMGenerator.SBOM_FILENAME)).exists()
outputContains "Hello, native!"
}
Expand Down Expand Up @@ -132,11 +129,11 @@ class SBOMFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
}
/**
* Validates the SBOM produced from 'java-application'.
* Validates the exported SBOM produced from 'java-application'.
* @param sbom path to the SBOM.
* @return true if validation succeeded.
*/
private static boolean validateSbom(File sbom) {
private static boolean validateExportedSBOM(File sbom) {
try {
if (!sbom.exists()) {
println "SBOM not found: ${sbom}"
Expand Down

0 comments on commit bee5ead

Please sign in to comment.