Skip to content

Commit

Permalink
add e2e test for sbomasm edit tools command
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Kumar Sahu <vivekkumarsahu650@gmail.com>
  • Loading branch information
viveksahu26 committed Dec 6, 2024
1 parent 05ee179 commit 852d5ad
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
64 changes: 64 additions & 0 deletions e2e/edit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package e2e_edit_test

import (
"io"
"os"
"path/filepath"
"testing"

"github.com/interlynk-io/sbomasm/cmd" // Replace with the actual import path
"github.com/rogpeppe/go-internal/testscript"
)

func TestSbomasmEdit(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}

t.Parallel()
testscript.Run(t, testscript.Params{
Dir: "testdata/edit",
RequireExplicitExec: true,
Setup: func(env *testscript.Env) error {
// copy required files to the workspace
if err := copyFile("testdata/edit/photon-lite.spdx.json", filepath.Join(env.WorkDir, "photon-lite.spdx.json")); err != nil {
return err
}
if err := copyFile("testdata/edit/expected-output-lite.spdx.json", filepath.Join(env.WorkDir, "expected-output-lite.spdx.json")); err != nil {
return err
}

return nil
},
})
}

func runSbomasm() int {
cmd.Execute()
return 0
}

func TestMain(m *testing.M) {
exitCode := testscript.RunMain(m, map[string]func() int{
"sbomasm": runSbomasm,
})
os.Exit(exitCode)
}

// Helper function to copy files
func copyFile(src, dst string) error {
sourceFile, err := os.Open(src)
if err != nil {
return err
}
defer sourceFile.Close()

destFile, err := os.Create(dst)
if err != nil {
return err
}
defer destFile.Close()

_, err = io.Copy(destFile, sourceFile)
return err
}
8 changes: 8 additions & 0 deletions e2e/testdata/edit/edit_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Run the 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

# Check that the output file exists
exists photon-missing.spdx.json

# Validate the output content matches the expected result
cmp photon-missing.spdx.json expected-output-lite.spdx.json
41 changes: 41 additions & 0 deletions e2e/testdata/edit/expected-output-lite.spdx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "Tern report for photon",
"documentNamespace": "https://spdx.org/spdxdocs/tern-report-b8e13d1780cd3a02204226bba3d0772d95da24a0-photon-21d2cd0a-064e-4198-8bf9-99882f2897aa",
"comment": "This document was generated by the Tern Project: https://github.com/tern-tools/tern",
"creationInfo": {
"licenseListVersion": "3.19",
"creators": [
"Tool: tern-b8e13d1780cd3a02204226bba3d0772d95da24a0",
"Tool: trivy-0.56.1",
"Tool: parlay-0.5.1",
"Tool: bomctl-v0.4.1",
"Tool: sbomasm-0.1.9"
],
"created": "2023-01-12T22:06:03Z"
},
"packages": [
{
"name": "photon",
"SPDXID": "SPDXRef-photon-3.0",
"versionInfo": "3.0",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": false,
"packageVerificationCode": {
"packageVerificationCodeValue": ""
},
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "NOASSERTION"
}
],
"relationships": [
{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-photon-3.0",
"relationshipType": "DESCRIBES"
}
]
}
33 changes: 33 additions & 0 deletions e2e/testdata/edit/photon-lite.spdx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"SPDXID": "SPDXRef-DOCUMENT",
"spdxVersion": "SPDX-2.2",
"creationInfo": {
"created": "2023-01-12T22:06:03Z",
"creators": ["Tool: tern-b8e13d1780cd3a02204226bba3d0772d95da24a0"],
"licenseListVersion": "3.19"
},
"name": "Tern report for photon",
"dataLicense": "CC0-1.0",
"comment": "This document was generated by the Tern Project: https://github.com/tern-tools/tern",
"documentNamespace": "https://spdx.org/spdxdocs/tern-report-b8e13d1780cd3a02204226bba3d0772d95da24a0-photon-21d2cd0a-064e-4198-8bf9-99882f2897aa",
"documentDescribes": ["SPDXRef-photon-3.0"],
"packages": [
{
"name": "photon",
"SPDXID": "SPDXRef-photon-3.0",
"versionInfo": "3.0",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": false,
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "NOASSERTION"
}
],
"relationships": [
{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-photon-3.0",
"relationshipType": "DESCRIBES"
}
]
}

0 comments on commit 852d5ad

Please sign in to comment.