Skip to content

Commit

Permalink
Revert "Removes GVKRequired struct (#400)" (#405)
Browse files Browse the repository at this point in the history
This reverts commit 5cbc9a0.

Signed-off-by: Mikalai Radchuk <[email protected]>
  • Loading branch information
m1kola authored Sep 11, 2023
1 parent 5cbc9a0 commit 1ea812b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
16 changes: 13 additions & 3 deletions internal/resolution/entities/bundle_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,23 @@ func (g GVK) String() string {
return fmt.Sprintf(`group:"%s" version:"%s" kind:"%s"`, g.Group, g.Version, g.Kind)
}

type GVKRequired property.GVKRequired

func (g GVKRequired) String() string {
return fmt.Sprintf(`group:"%s" version:"%s" kind:"%s"`, g.Group, g.Version, g.Kind)
}

func (g GVKRequired) AsGVK() GVK {
return GVK(g)
}

type BundleEntity struct {
*input.Entity

// these properties are lazy loaded as they are requested
bundlePackage *property.Package
providedGVKs []GVK
requiredGVKs []GVK
requiredGVKs []GVKRequired
requiredPackages []PackageRequired
channel *property.Channel
channelEntry *ChannelEntry
Expand Down Expand Up @@ -91,7 +101,7 @@ func (b *BundleEntity) ProvidedGVKs() ([]GVK, error) {
return b.providedGVKs, nil
}

func (b *BundleEntity) RequiredGVKs() ([]GVK, error) {
func (b *BundleEntity) RequiredGVKs() ([]GVKRequired, error) {
if err := b.loadRequiredGVKs(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -204,7 +214,7 @@ func (b *BundleEntity) loadRequiredGVKs() error {
b.mu.Lock()
defer b.mu.Unlock()
if b.requiredGVKs == nil {
requiredGVKs, err := loadFromEntity[[]GVK](b.Entity, property.TypeGVKRequired, optional)
requiredGVKs, err := loadFromEntity[[]GVKRequired](b.Entity, property.TypeGVKRequired, optional)
if err != nil {
return fmt.Errorf("error determining bundle required gvks for entity '%s': %w", b.ID, err)
}
Expand Down
23 changes: 22 additions & 1 deletion internal/resolution/entities/bundle_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var _ = Describe("BundleEntity", func() {
bundleEntity := olmentity.NewBundleEntity(entity)
requiredGvks, err := bundleEntity.RequiredGVKs()
Expect(err).ToNot(HaveOccurred())
Expect(requiredGvks).To(Equal([]olmentity.GVK{
Expect(requiredGvks).To(Equal([]olmentity.GVKRequired{
{Group: "foo.io", Kind: "Foo", Version: "v1"},
{Group: "bar.io", Kind: "Bar", Version: "v1alpha1"},
}))
Expand Down Expand Up @@ -326,6 +326,27 @@ var _ = Describe("BundleEntity", func() {
})
})

// Increase test coverage
Describe("GVKRequired properties", func() {
It("should return the GVKRequired properties", func() {
gvk := olmentity.GVKRequired{
Group: "foo.io",
Kind: "Foo",
Version: "v1",
}
Expect(gvk.AsGVK().Version).To(Equal("v1"))
Expect(gvk.AsGVK().Group).To(Equal("foo.io"))
Expect(gvk.AsGVK().Kind).To(Equal("Foo"))
})
It("should return the GVKRequired properties as a string", func() {
gvk := olmentity.GVKRequired{
Group: "foo.io",
Kind: "Foo",
Version: "v1",
}
Expect(gvk.String()).To(Equal(`group:"foo.io" version:"v1" kind:"Foo"`))
})
})
Describe("GVK properties", func() {
It("should return the gvk properties", func() {
gvk := olmentity.GVK{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (b *BundlesAndDepsVariableSource) getEntityDependencies(ctx context.Context
// todo(perdasilva): disambiguate between not found and actual errors
gvkDependencies, _ := bundleEntity.RequiredGVKs()
for i := 0; i < len(gvkDependencies); i++ {
providedGvk := gvkDependencies[i]
providedGvk := gvkDependencies[i].AsGVK()
gvkDependencyBundles, err := entitySource.Filter(ctx, predicates.ProvidesGVK(&providedGvk))
if err != nil {
return nil, err
Expand Down

0 comments on commit 1ea812b

Please sign in to comment.