mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
add test and linting fixes
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -46,6 +46,7 @@ func (p *packageMetadataUnpacker) String() string {
|
||||
}
|
||||
|
||||
// UnmarshalJSON is a custom unmarshaller for handling basic values and values with ambiguous types.
|
||||
// nolint:funlen
|
||||
func (p *Package) UnmarshalJSON(b []byte) error {
|
||||
var basic PackageBasicData
|
||||
if err := json.Unmarshal(b, &basic); err != nil {
|
||||
|
||||
@@ -24,13 +24,8 @@ func ToFormatModel(catalog *pkg.Catalog, srcMetadata *source.Metadata, d *distro
|
||||
log.Warnf("unable to create syft-json source object: %+v", err)
|
||||
}
|
||||
|
||||
artifacts, err := toPackageModels(catalog)
|
||||
if err != nil {
|
||||
return model.Document{}
|
||||
}
|
||||
|
||||
return model.Document{
|
||||
Artifacts: artifacts,
|
||||
Artifacts: toPackageModels(catalog),
|
||||
ArtifactRelationships: toRelationshipModel(pkg.NewRelationships(catalog)),
|
||||
Source: src,
|
||||
Distro: toDistroModel(d),
|
||||
@@ -46,23 +41,19 @@ func ToFormatModel(catalog *pkg.Catalog, srcMetadata *source.Metadata, d *distro
|
||||
}
|
||||
}
|
||||
|
||||
func toPackageModels(catalog *pkg.Catalog) ([]model.Package, error) {
|
||||
func toPackageModels(catalog *pkg.Catalog) []model.Package {
|
||||
artifacts := make([]model.Package, 0)
|
||||
if catalog == nil {
|
||||
return artifacts, nil
|
||||
return artifacts
|
||||
}
|
||||
for _, p := range catalog.Sorted() {
|
||||
art, err := toPackageModel(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
artifacts = append(artifacts, art)
|
||||
artifacts = append(artifacts, toPackageModel(p))
|
||||
}
|
||||
return artifacts, nil
|
||||
return artifacts
|
||||
}
|
||||
|
||||
// toPackageModel crates a new Package from the given pkg.Package.
|
||||
func toPackageModel(p *pkg.Package) (model.Package, error) {
|
||||
func toPackageModel(p *pkg.Package) model.Package {
|
||||
var cpes = make([]string, len(p.CPEs))
|
||||
for i, c := range p.CPEs {
|
||||
cpes[i] = c.BindToFmtString()
|
||||
@@ -96,7 +87,7 @@ func toPackageModel(p *pkg.Package) (model.Package, error) {
|
||||
MetadataType: p.MetadataType,
|
||||
Metadata: p.Metadata,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func toRelationshipModel(relationships []pkg.Relationship) []model.Relationship {
|
||||
|
||||
Reference in New Issue
Block a user