Introduce new format pattern + port json processing (#550)

* add new format pattern

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add syftjson format

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add internal formats helper

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add SBOM encode/decode to lib API

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* remove json presenter + update presenter tests to use common utils

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* remove presenter format enum type + add formats shim in presenter helper

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add MustCPE helper for tests

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* update usage of format enum

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add test fixtures for encode/decode tests

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* fix integration test

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* migrate format detection to use reader

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* address review comments

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-10-20 21:36:34 +00:00
committed by GitHub
parent 5e315c0f17
commit 560b05c2c9
57 changed files with 3139 additions and 421 deletions
@@ -3,10 +3,11 @@ package integration
import (
"bytes"
"encoding/json"
exportedPackages "github.com/anchore/syft/syft/presenter/packages"
"testing"
internalPackages "github.com/anchore/syft/internal/presenter/packages"
syftjsonModel "github.com/anchore/syft/internal/formats/syftjson/model"
"github.com/anchore/syft/syft/format"
exportedPackages "github.com/anchore/syft/syft/presenter/packages"
)
func TestPackageOwnershipRelationships(t *testing.T) {
@@ -24,7 +25,7 @@ func TestPackageOwnershipRelationships(t *testing.T) {
t.Run(test.fixture, func(t *testing.T) {
catalog, d, src := catalogFixtureImage(t, test.fixture)
p := exportedPackages.Presenter(exportedPackages.JSONPresenterOption, exportedPackages.PresenterConfig{
p := exportedPackages.Presenter(format.JSONOption, exportedPackages.PresenterConfig{
SourceMetadata: src.Metadata,
Catalog: catalog,
Distro: d,
@@ -39,7 +40,7 @@ func TestPackageOwnershipRelationships(t *testing.T) {
t.Fatalf("unable to present: %+v", err)
}
var doc internalPackages.JSONDocument
var doc syftjsonModel.Document
decoder := json.NewDecoder(output)
if err := decoder.Decode(&doc); err != nil {
t.Fatalf("unable to decode json doc: %+v", err)