mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
package python
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/anchore/imgbom/imgbom/pkg"
|
|
)
|
|
|
|
func assertPkgsEqual(t *testing.T, actual []pkg.Package, expected map[string]pkg.Package) {
|
|
t.Helper()
|
|
if len(actual) != 1 {
|
|
for _, a := range actual {
|
|
t.Log(" ", a)
|
|
}
|
|
t.Fatalf("unexpected package count: %d!=%d", len(actual), 1)
|
|
}
|
|
|
|
for _, a := range actual {
|
|
expectedPkg, ok := expected[a.Name]
|
|
if !ok {
|
|
t.Errorf("unexpected package found: '%s'", a.Name)
|
|
}
|
|
|
|
if expectedPkg.Version != a.Version {
|
|
t.Errorf("unexpected package version: '%s'", a.Version)
|
|
}
|
|
|
|
if a.Language != expectedPkg.Language {
|
|
t.Errorf("bad language: '%+v'", a.Language)
|
|
}
|
|
|
|
if a.Type != expectedPkg.Type {
|
|
t.Errorf("bad package type: %+v", a.Type)
|
|
}
|
|
|
|
if len(a.Licenses) < 1 {
|
|
t.Errorf("bad package licenses count: '%+v'", a.Licenses)
|
|
} else if a.Licenses[0] != expectedPkg.Licenses[0] {
|
|
t.Errorf("bad package licenses: '%+v'", a.Licenses)
|
|
}
|
|
|
|
}
|
|
}
|
|
func TestParseEggMetadata(t *testing.T) {
|
|
expected := map[string]pkg.Package{
|
|
"requests": {
|
|
Name: "requests",
|
|
Version: "2.22.0",
|
|
Language: pkg.Python,
|
|
Type: pkg.EggPkg,
|
|
Licenses: []string{"Apache 2.0"},
|
|
},
|
|
}
|
|
fixture, err := os.Open("test-fixtures/egg-info/PKG-INFO")
|
|
if err != nil {
|
|
t.Fatalf("failed to open fixture: %+v", err)
|
|
}
|
|
|
|
actual, err := parseEggMetadata(fixture)
|
|
if err != nil {
|
|
t.Fatalf("failed to parse egg-info: %+v", err)
|
|
}
|
|
|
|
assertPkgsEqual(t, actual, expected)
|
|
|
|
}
|
|
|
|
func TestParseWheelMetadata(t *testing.T) {
|
|
expected := map[string]pkg.Package{
|
|
"Pygments": {
|
|
Name: "Pygments",
|
|
Version: "2.6.1",
|
|
Language: pkg.Python,
|
|
Type: pkg.WheelPkg,
|
|
Licenses: []string{"BSD License"},
|
|
},
|
|
}
|
|
fixture, err := os.Open("test-fixtures/dist-info/METADATA")
|
|
if err != nil {
|
|
t.Fatalf("failed to open fixture: %+v", err)
|
|
}
|
|
|
|
actual, err := parseWheelMetadata(fixture)
|
|
if err != nil {
|
|
t.Fatalf("failed to parse dist-info: %+v", err)
|
|
}
|
|
|
|
assertPkgsEqual(t, actual, expected)
|
|
|
|
}
|