Skip to content

Commit

Permalink
Ent - HasMetadata: fix ingesting same twice (#1392)
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <mrizzi@redhat.com>
  • Loading branch information
mrizzi committed Oct 13, 2023
1 parent ff8bcb9 commit 64850de
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/assembler/backends/ent/backend/hasMetadata.go
Expand Up @@ -236,7 +236,7 @@ func toModelHasMetadata(v *ent.HasMetadata) *model.HasMetadata {
func hasMetadataInputPredicate(subject model.PackageSourceOrArtifactInput, pkgMatchType *model.MatchFlags, filter model.HasMetadataInputSpec) predicate.HasMetadata {
var subjectSpec *model.PackageSourceOrArtifactSpec
if subject.Package != nil {
if pkgMatchType != nil || pkgMatchType.Pkg == model.PkgMatchTypeAllVersions {
if pkgMatchType != nil && pkgMatchType.Pkg == model.PkgMatchTypeAllVersions {
subject.Package.Version = nil
}
subjectSpec = &model.PackageSourceOrArtifactSpec{
Expand Down
37 changes: 37 additions & 0 deletions pkg/assembler/backends/ent/backend/hasMetadata_test.go
Expand Up @@ -203,6 +203,43 @@ func (s *Suite) TestHasMetadata() {
},
},
},
{
Name: "Ingest same twice with version",
InPkg: []*model.PkgInputSpec{p2},
Calls: []call{
{
Sub: model.PackageSourceOrArtifactInput{
Package: p2,
},
Match: &model.MatchFlags{
Pkg: model.PkgMatchTypeSpecificVersion,
},
HM: &model.HasMetadataInputSpec{
Justification: "test justification",
},
},
{
Sub: model.PackageSourceOrArtifactInput{
Package: p2,
},
Match: &model.MatchFlags{
Pkg: model.PkgMatchTypeSpecificVersion,
},
HM: &model.HasMetadataInputSpec{
Justification: "test justification",
},
},
},
Query: &model.HasMetadataSpec{
Justification: ptrfrom.String("test justification"),
},
ExpHM: []*model.HasMetadata{
{
Subject: p2out,
Justification: "test justification",
},
},
},
{
Name: "Ingest two different keys",
InPkg: []*model.PkgInputSpec{p1},
Expand Down

0 comments on commit 64850de

Please sign in to comment.