Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add e2e test for auto addition of sbomasm as a tool on edit #123

Conversation

viveksahu26
Copy link
Contributor

@viveksahu26 viveksahu26 commented Dec 8, 2024

This PR add the e2e test for addition of sbomasm tool automatically on edit if and only if:

  • it is not present
  • or sbomasm with different version.

Added e2e test:

Our Requirements:

1. We wanted to write a robust and automated test for the sbomasm edit command.

  • We wanted to:

    go run main.go edit --missing --subject document --tool 'trivy (0.56.1)' --tool 'parlay (0.5.1)' --tool 'bomctl (v0.4.1)' photon-lite.spdx.json --output expected-output-lite.spdx.json
    • Validate the generated output file (photon-missing.spdx.json). --> This file(actual result or actual file) will be generated during test execution.
    • Compare the generated file against an expected result (expected-output-lite.spdx.json). --> we will provide this file(expected result or expected file).

2. We choose testscript test library

  • Why ?
    • It allows tests to run in an isolated temporary workspace ($WORK),
    • It provides simple and powerful commands like exec, exists, and cmp for script-based testing. cmp command ensures the generated file matches the expected result

3. Implementation

  • Using testscript, we created a directory structure and test script:

  • edit_test.go

    • Defined how the test environment is set up (Setup) :
      • Like copy the files which will be required to execute the command, say, photon-lite.spdx.json file is required when executing sbomasm edit command.
      • Similarly, copy the 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 of sbomasm edit command.
      • The sbomasm command is mapped to cmd.Execute(): which will be used inside edit_test.txt script.
  • edit_test.txt

    • Defined the script to be run in the isolated workspace.:

      • Run the actual command(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:

      • The test passes if:
      • photon-missing.spdx.json is created successfully.
      • The generated file photon-missing.spdx.json matches expected-output-lite.spdx.json.

@riteshnoronha riteshnoronha merged commit c4819f6 into interlynk-io:main Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants