mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* migrate pkg.ID and pkg.Relationship to artifact package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * return relationships from tasks Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix more tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add artifact.Identifiable by Identity() method Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove catalog ID assignment Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * adjust spdx helpers to use copy of packages Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * stabilize package ID relative to encode-decode format cycles Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * rename Identity() to ID() Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * use zero value for nils in ID generation Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * enable source.Location to be identifiable Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * hoist up package relationship discovery to analysis stage Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update ownership-by-file-overlap relationship description Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add test reminders to put new relationships under test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * adjust PHP composer.lock parser function to return relationships Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package syftjson
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/anchore/syft/internal/formats/common/testutils"
|
|
"github.com/go-test/deep"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEncodeDecodeCycle(t *testing.T) {
|
|
testImage := "image-simple"
|
|
originalSBOM := testutils.ImageInput(t, testImage)
|
|
|
|
var buf bytes.Buffer
|
|
assert.NoError(t, encoder(&buf, originalSBOM))
|
|
|
|
actualSBOM, err := decoder(bytes.NewReader(buf.Bytes()))
|
|
assert.NoError(t, err)
|
|
|
|
for _, d := range deep.Equal(originalSBOM.Source, actualSBOM.Source) {
|
|
t.Errorf("metadata difference: %+v", d)
|
|
}
|
|
|
|
actualPackages := actualSBOM.Artifacts.PackageCatalog.Sorted()
|
|
for idx, p := range originalSBOM.Artifacts.PackageCatalog.Sorted() {
|
|
if !assert.Equal(t, p.Name, actualPackages[idx].Name) {
|
|
t.Errorf("different package at idx=%d: %s vs %s", idx, p.Name, actualPackages[idx].Name)
|
|
continue
|
|
}
|
|
|
|
for _, d := range deep.Equal(p, actualPackages[idx]) {
|
|
if strings.Contains(d, ".VirtualPath: ") {
|
|
// location.Virtual path is not exposed in the json output
|
|
continue
|
|
}
|
|
if strings.HasSuffix(d, "<nil slice> != []") {
|
|
// semantically the same
|
|
continue
|
|
}
|
|
t.Errorf("package difference (%s): %+v", p.Name, d)
|
|
}
|
|
}
|
|
}
|