Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: make no-op legacy claims finder comply with interface expectations #60

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/construct/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
// TODO: add sender / publisher / linksystem
legacyClaims := cfg.legacyClaims
if legacyClaims == nil {
legacyClaims = providerindex.NewNotFoundLegacyClaimsFinder()
legacyClaims = providerindex.NewNoResultsLegacyClaimsFinder()

Check warning on line 338 in pkg/construct/construct.go

View check run for this annotation

Codecov / codecov/patch

pkg/construct/construct.go#L338

Added line #L338 was not covered by tests
}
providerIndex := providerindex.New(providersCache, findClient, publisher, legacyClaims)

Expand Down
18 changes: 10 additions & 8 deletions pkg/service/providerindex/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

// LegacyClaimsFinder is a read-only interface to find claims on a legacy system
type LegacyClaimsFinder interface {
// Find returns a list of claims for a given content hash.
// Implementations should return an empty slice and no error if no results are found.
Find(ctx context.Context, contentHash multihash.Multihash) ([]model.ProviderResult, error)
}

Expand Down Expand Up @@ -260,15 +262,15 @@
}, nil
}

// NotFoundLegacyClaimsFinder is a LegacyClaimsFinder that always returns ErrKeyNotFound. It can be used when accessing
// claims in a legacy system is not required
type NotFoundLegacyClaimsFinder struct{}
// NoResultsLegacyClaimsFinder is a LegacyClaimsFinder that returns no results. It can be used when accessing claims
// in a legacy system is not required
type NoResultsLegacyClaimsFinder struct{}

func NewNotFoundLegacyClaimsFinder() NotFoundLegacyClaimsFinder {
return NotFoundLegacyClaimsFinder{}
func NewNoResultsLegacyClaimsFinder() NoResultsLegacyClaimsFinder {
return NoResultsLegacyClaimsFinder{}

Check warning on line 270 in pkg/service/providerindex/legacy.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/providerindex/legacy.go#L269-L270

Added lines #L269 - L270 were not covered by tests
}

// Find always returns ErrKeyNotFound
func (f NotFoundLegacyClaimsFinder) Find(ctx context.Context, contentHash multihash.Multihash) ([]model.ProviderResult, error) {
return nil, types.ErrKeyNotFound
// Find always returns no results
func (f NoResultsLegacyClaimsFinder) Find(ctx context.Context, contentHash multihash.Multihash) ([]model.ProviderResult, error) {
return []model.ProviderResult{}, nil

Check warning on line 275 in pkg/service/providerindex/legacy.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/providerindex/legacy.go#L274-L275

Added lines #L274 - L275 were not covered by tests
}
Loading