mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
tests: verify requirements.txt captures versions
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
83056a4b6f
commit
f8a2b7a626
39
imgbom/cataloger/python/parse_requirements_test.go
Normal file
39
imgbom/cataloger/python/parse_requirements_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package python
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/anchore/imgbom/imgbom/pkg"
|
||||
)
|
||||
|
||||
func TestParseRequirementsTxt(t *testing.T) {
|
||||
expected := map[string]pkg.Package{
|
||||
"foo": {
|
||||
Name: "foo",
|
||||
Version: "1.0.0",
|
||||
Language: pkg.Python,
|
||||
Type: pkg.PythonRequirementsPkg,
|
||||
Licenses: []string{},
|
||||
},
|
||||
"flask": {
|
||||
Name: "flask",
|
||||
Version: "4.0.0",
|
||||
Language: pkg.Python,
|
||||
Type: pkg.PythonRequirementsPkg,
|
||||
Licenses: []string{},
|
||||
},
|
||||
}
|
||||
fixture, err := os.Open("test-fixtures/requires/requirements.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open fixture: %+v", err)
|
||||
}
|
||||
|
||||
actual, err := parseRequirementsTxt(fixture.Name(), fixture)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse requirements: %+v", err)
|
||||
}
|
||||
|
||||
assertPkgsEqual(t, actual, expected)
|
||||
|
||||
}
|
||||
@ -9,11 +9,11 @@ import (
|
||||
|
||||
func assertPkgsEqual(t *testing.T, actual []pkg.Package, expected map[string]pkg.Package) {
|
||||
t.Helper()
|
||||
if len(actual) != 1 {
|
||||
if len(actual) != len(expected) {
|
||||
for _, a := range actual {
|
||||
t.Log(" ", a)
|
||||
}
|
||||
t.Fatalf("unexpected package count: %d!=%d", len(actual), 1)
|
||||
t.Fatalf("unexpected package count: %d!=%d", len(actual), len(expected))
|
||||
}
|
||||
|
||||
for _, a := range actual {
|
||||
@ -34,10 +34,13 @@ func assertPkgsEqual(t *testing.T, actual []pkg.Package, expected map[string]pkg
|
||||
t.Errorf("bad package type: %+v", a.Type)
|
||||
}
|
||||
|
||||
if len(a.Licenses) < 1 {
|
||||
if len(a.Licenses) < len(expectedPkg.Licenses) {
|
||||
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)
|
||||
}
|
||||
if len(a.Licenses) > 0 {
|
||||
if a.Licenses[0] != expectedPkg.Licenses[0] {
|
||||
t.Errorf("bad package licenses: '%+v'", a.Licenses)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
flask == 4.0.0
|
||||
# a line that is ignored
|
||||
sqlalchemy >= 1.0.0
|
||||
foo == 1.0.0 # a comment that needs to be ignored
|
||||
-e https://github.com/pecan/pecan.git
|
||||
-r other-requirements.txt
|
||||
--requirements super-secretrequirements.txt
|
||||
Loading…
x
Reference in New Issue
Block a user