diff --git a/internal/catalogmetadata/sort/sort_test.go b/internal/catalogmetadata/sort/sort_test.go index 9d1e2e275..d8dabbb0b 100644 --- a/internal/catalogmetadata/sort/sort_test.go +++ b/internal/catalogmetadata/sort/sort_test.go @@ -131,4 +131,33 @@ func TestByDeprecated(t *testing.T) { require.Len(t, toSort, 2) assert.Equal(t, b2, toSort[0]) assert.Equal(t, b1, toSort[1]) + + b1.Deprecations = []declcfg.DeprecationEntry{ + { + Reference: declcfg.PackageScopedReference{ + Schema: "olm.package", + }, + }, + } + b2.Deprecations = append(b2.Deprecations, declcfg.DeprecationEntry{ + Reference: declcfg.PackageScopedReference{ + Schema: "olm.package", + }, + }, declcfg.DeprecationEntry{ + Reference: declcfg.PackageScopedReference{ + Schema: "olm.bundle", + Name: "baz", + }, + }) + + toSort = []*catalogmetadata.Bundle{b2, b1} + sort.SliceStable(toSort, func(i, j int) bool { + return catalogsort.ByDeprecated(toSort[i], toSort[j]) + }) + // Both are deprecated at package level, b2 is deprecated + // explicitly, b2 should be preferred less + require.Len(t, toSort, 2) + assert.Equal(t, b1, toSort[0]) + assert.Equal(t, b2, toSort[1]) + } diff --git a/internal/catalogmetadata/types.go b/internal/catalogmetadata/types.go index 05457a573..1d8b8e0fa 100644 --- a/internal/catalogmetadata/types.go +++ b/internal/catalogmetadata/types.go @@ -166,16 +166,6 @@ func (b *Bundle) HasDeprecation() bool { // are deprecated and there should be no special treatment func (b *Bundle) IsDeprecated() bool { for _, dep := range b.Deprecations { - // references with the olm.package schema don't specify a name - // so we assume it is correctly associated with this bundle. - // We return false here so no special considerations are taken - // regarding deprecation status when the entire package is deprecated. - // Resolution when the package is deprecated is equivalent - // to resolution when nothing is deprecated - if dep.Reference.Schema == declcfg.SchemaPackage { - return false - } - if dep.Reference.Schema == declcfg.SchemaBundle && dep.Reference.Name == b.Name { return true }