Skip to content

Commit

Permalink
add test for Package() func
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Aug 29, 2023
1 parent 3461623 commit de0a631
Showing 1 changed file with 100 additions and 1 deletion.
101 changes: 100 additions & 1 deletion pkg/purl/purl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ func TestNewPackageURL(t *testing.T) {
}

func TestFromString(t *testing.T) {

testCases := []struct {
name string
purl string
Expand Down Expand Up @@ -561,3 +560,103 @@ func TestFromString(t *testing.T) {
})
}
}

func TestPackage(t *testing.T) {
tests := []struct {
name string
pkgURL *purl.PackageURL
wantPkg *ftypes.Package
}{
{
name: "rpm + Qualifiers",
pkgURL: &purl.PackageURL{
PackageURL: packageurl.PackageURL{
Type: packageurl.TypeRPM,
Namespace: "redhat",
Name: "nodejs-full-i18n",
Version: "10.21.0-3.module_el8.2.0+391+8da3adc6",
Qualifiers: packageurl.Qualifiers{
{
Key: "arch",
Value: "x86_64",
},
{
Key: "epoch",
Value: "1",
},
{
Key: "modularitylabel",
Value: "nodejs:10:8020020200707141642:6a468ee4",
},
{
Key: "distro",
Value: "redhat-8",
},
},
},
},
wantPkg: &ftypes.Package{
Name: "nodejs-full-i18n",
Version: "10.21.0",
Release: "3.module_el8.2.0+391+8da3adc6",
Arch: "x86_64",
Epoch: 1,
Modularitylabel: "nodejs:10:8020020200707141642:6a468ee4",
},
},
{
name: "composer with namespace",
pkgURL: &purl.PackageURL{
PackageURL: packageurl.PackageURL{
Type: packageurl.TypeComposer,
Namespace: "symfony",
Name: "contracts",
Version: "v1.0.2",
},
},
wantPkg: &ftypes.Package{
Name: "symfony/contracts",
Version: "v1.0.2",
},
},
{
name: "maven with namespace",
pkgURL: &purl.PackageURL{
PackageURL: packageurl.PackageURL{
Type: packageurl.TypeMaven,
Namespace: "org.springframework",
Name: "spring-core",
Version: "5.0.4.RELEASE",
Qualifiers: packageurl.Qualifiers{},
},
},
wantPkg: &ftypes.Package{
Name: "org.springframework:spring-core",
Version: "5.0.4.RELEASE",
},
},
{
name: "cocoapods with subpath",
pkgURL: &purl.PackageURL{
PackageURL: packageurl.PackageURL{
Type: packageurl.TypeCocoapods,
Version: "4.2.0",
Name: "AppCenter",
Subpath: "Analytics",
Qualifiers: packageurl.Qualifiers{},
},
},
wantPkg: &ftypes.Package{
Name: "AppCenter/Analytics",
Version: "4.2.0",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.pkgURL.Package()
assert.Equal(t, tt.wantPkg, got)
})
}
}

0 comments on commit de0a631

Please sign in to comment.