Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
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
7 changes: 4 additions & 3 deletions pkg/deppy/input/cache_entity_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package input

import (
"context"
"fmt"

"github.com/operator-framework/deppy/pkg/deppy"
)
Expand All @@ -19,11 +20,11 @@ func NewCacheQuerier(entities map[deppy.Identifier]Entity) *CacheEntitySource {
}
}

func (c CacheEntitySource) Get(_ context.Context, id deppy.Identifier) *Entity {
func (c CacheEntitySource) Get(_ context.Context, id deppy.Identifier) (*Entity, error) {
if entity, ok := c.entities[id]; ok {
return &entity
return &entity, nil
}
return nil
return nil, fmt.Errorf("entity with id: %s not found in the entity source", id.String())
}

func (c CacheEntitySource) Filter(_ context.Context, filter Predicate) (EntityList, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/deppy/input/entity_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type EntityListMap map[string]EntityList

// EntitySource provides a query and content acquisition interface for arbitrary entity stores
type EntitySource interface {
Get(ctx context.Context, id deppy.Identifier) *Entity
Get(ctx context.Context, id deppy.Identifier) (*Entity, error)
Filter(ctx context.Context, filter Predicate) (EntityList, error)
GroupBy(ctx context.Context, fn GroupByFunction) (EntityListMap, error)
Iterate(ctx context.Context, fn IteratorFunction) error
Expand Down
10 changes: 9 additions & 1 deletion pkg/deppy/input/entity_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@ var _ = Describe("EntitySource", func() {

Describe("Get", func() {
It("should return requested entity", func() {
e := entitySource.Get(context.Background(), "2-2")
e, err := entitySource.Get(context.Background(), "2-2")
Expect(err).To(BeNil())
Expect(e).NotTo(BeNil())
Expect(e.Identifier()).To(Equal(deppy.Identifier("2-2")))
})

It("should return an error when the requested entity is not found", func() {
e, err := entitySource.Get(context.Background(), "random")
Expect(err).To(HaveOccurred())
Expect(e).To(BeNil())
Expect(err.Error()).To(BeEquivalentTo(fmt.Sprintf("entity with id: %s not found in the entity source", "random")))
})
})

Describe("Filter", func() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ext/olm/constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ type MockQuerier struct {
testEntityList input.EntityList
}

func (t MockQuerier) Get(_ context.Context, _ deppy.Identifier) *input.Entity {
return &input.Entity{}
func (t MockQuerier) Get(_ context.Context, _ deppy.Identifier) (*input.Entity, error) {
return &input.Entity{}, nil
}
func (t MockQuerier) Filter(_ context.Context, filter input.Predicate) (input.EntityList, error) {
if t.testError != nil {
Expand Down