mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 08:53:15 +01:00
95 lines
2.2 KiB
Go
95 lines
2.2 KiB
Go
package java
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/go-test/deep"
|
|
)
|
|
|
|
func TestParseJavaPomProperties(t *testing.T) {
|
|
tests := []struct {
|
|
expected pkg.PomProperties
|
|
}{
|
|
{
|
|
expected: pkg.PomProperties{
|
|
Path: "test-fixtures/pom/small.pom.properties",
|
|
GroupID: "org.anchore",
|
|
ArtifactID: "example-java-app-maven",
|
|
Version: "0.1.0",
|
|
Extra: map[string]string{},
|
|
},
|
|
},
|
|
{
|
|
expected: pkg.PomProperties{
|
|
Path: "test-fixtures/pom/extra.pom.properties",
|
|
GroupID: "org.anchore",
|
|
ArtifactID: "example-java-app-maven",
|
|
Version: "0.1.0",
|
|
Name: "something-here",
|
|
Extra: map[string]string{
|
|
"another": "thing",
|
|
"sweet": "work",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
expected: pkg.PomProperties{
|
|
Path: "test-fixtures/pom/colon-delimited.pom.properties",
|
|
GroupID: "org.anchore",
|
|
ArtifactID: "example-java-app-maven",
|
|
Version: "0.1.0",
|
|
Extra: map[string]string{},
|
|
},
|
|
},
|
|
{
|
|
expected: pkg.PomProperties{
|
|
Path: "test-fixtures/pom/equals-delimited-with-colons.pom.properties",
|
|
GroupID: "org.anchore",
|
|
ArtifactID: "example-java:app-maven",
|
|
Version: "0.1.0:something",
|
|
Extra: map[string]string{},
|
|
},
|
|
},
|
|
{
|
|
expected: pkg.PomProperties{
|
|
Path: "test-fixtures/pom/colon-delimited-with-equals.pom.properties",
|
|
GroupID: "org.anchore",
|
|
ArtifactID: "example-java=app-maven",
|
|
Version: "0.1.0=something",
|
|
Extra: map[string]string{},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.expected.Path, func(t *testing.T) {
|
|
fixture, err := os.Open(test.expected.Path)
|
|
if err != nil {
|
|
t.Fatalf("could not open fixture: %+v", err)
|
|
}
|
|
|
|
actual, err := parsePomProperties(fixture.Name(), fixture)
|
|
if err != nil {
|
|
t.Fatalf("failed to parse manifest: %+v", err)
|
|
}
|
|
|
|
diffs := deep.Equal(actual, &test.expected)
|
|
if len(diffs) > 0 {
|
|
for _, d := range diffs {
|
|
t.Errorf("diff: %+v", d)
|
|
}
|
|
|
|
b, err := json.MarshalIndent(actual, "", " ")
|
|
if err != nil {
|
|
t.Fatalf("can't show results: %+v", err)
|
|
}
|
|
|
|
t.Errorf("full result: %s", string(b))
|
|
}
|
|
})
|
|
}
|
|
}
|