-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: knqyf263 <[email protected]>
- Loading branch information
Showing
3 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,7 +585,7 @@ func TestFromString(t *testing.T) { | |
} | ||
} | ||
|
||
func TestToPackage(t *testing.T) { | ||
func TestPackageURL_Package(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
pkgURL *purl.PackageURL | ||
|
@@ -769,7 +769,7 @@ func TestToPackage(t *testing.T) { | |
} | ||
} | ||
|
||
func TestLangType(t *testing.T) { | ||
func TestPackageURL_LangType(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
purl packageurl.PackageURL | ||
|
@@ -812,3 +812,72 @@ func TestLangType(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestPackageURL_Match(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
constraint string | ||
target string | ||
want bool | ||
}{ | ||
{ | ||
name: "same purl", | ||
constraint: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
target: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
want: true, | ||
}, | ||
{ | ||
name: "different type", | ||
constraint: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
target: "pkg:maven/github.com/aquasecurity/[email protected]", | ||
want: false, | ||
}, | ||
{ | ||
name: "different namespace", | ||
constraint: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
target: "pkg:golang/github.com/aquasecurity2/[email protected]", | ||
want: false, | ||
}, | ||
{ | ||
name: "different name", | ||
constraint: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
target: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
want: false, | ||
}, | ||
{ | ||
name: "different version", | ||
constraint: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
target: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
want: false, | ||
}, | ||
{ | ||
name: "version wildcard", | ||
constraint: "pkg:golang/github.com/aquasecurity/trivy", | ||
target: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
want: true, | ||
}, | ||
{ | ||
name: "different qualifier", | ||
constraint: "pkg:bitnami/[email protected]?arch=arm64&distro=debian-12", | ||
target: "pkg:bitnami/[email protected]?arch=arm64&distro=debian-13", | ||
want: false, | ||
}, | ||
{ | ||
name: "target more qualifiers", | ||
constraint: "pkg:bitnami/[email protected]?arch=arm64", | ||
target: "pkg:bitnami/[email protected]?arch=arm64&distro=debian-13", | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
c, err := purl.FromString(tt.constraint) | ||
require.NoError(t, err) | ||
|
||
p, err := purl.FromString(tt.target) | ||
require.NoError(t, err) | ||
|
||
assert.Equalf(t, tt.want, c.Match(p.Unwrap()), "Match()") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters