add e2e test for auto addition of sbomasm as a tool on edit #123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR add the e2e test for addition of sbomasm tool automatically on edit if and only if:
Added e2e test:
Our Requirements:
1. We wanted to write a robust and automated test for the
sbomasm edit
command.We wanted to:
photon-missing.spdx.json
). --> This file(actual result or actual file) will be generated during test execution.expected-output-lite.spdx.json
). --> we will provide this file(expected result or expected file).2. We choose
testscript
test libraryexec
,exists
, andcmp
for script-based testing.cmp
command ensures the generated file matches the expected result3. Implementation
Using testscript, we created a directory structure and test script:
edit_test.go
photon-lite.spdx.json
file is required when executingsbomasm edit
command.expected-output-lite.spdx.json
, which will be later on used to compare the o/p of this file with actually obtained file after execution ofsbomasm edit
command.sbomasm
command is mapped to cmd.Execute(): which will be used insideedit_test.txt
script.edit_test.txt
Defined the script to be run in the isolated workspace.:
exec
):sbomasm edit
command.exec sbomasm edit --missing --subject document --tool 'trivy (0.56.1)' --tool 'parlay (0.5.1)' --tool 'bomctl (v0.4.1)' photon-lite.spdx.json --output photon-missing.spdx.json
Validation:
photon-missing.spdx.json
is created successfully.photon-missing.spdx.json
matches expected-output-lite.spdx.json.