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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions e2e/edit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package e2e_edit_test

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

"github.com/interlynk-io/sbomasm/cmd"

"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"
}
]
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ require (

require golang.org/x/mod v0.22.0 // indirect

require golang.org/x/tools v0.22.0 // indirect

require (
github.com/DependencyTrack/client-go v0.14.0
github.com/ProtonMail/go-crypto v1.1.3 // indirect
Expand All @@ -31,7 +33,7 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rogpeppe/go-internal v1.13.1
github.com/spdx/gordf v0.0.0-20221230105357-b735bd5aac89 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
Loading