Skip to content

Commit

Permalink
Add unit test to query_test to up coverage
Browse files Browse the repository at this point in the history
Signed-off-by: perdasilva <perdasilva@redhat.com>
  • Loading branch information
perdasilva committed Jul 4, 2022
1 parent 8250533 commit 716dbd1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/registry/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"testing/fstest"

"github.com/operator-framework/operator-registry/alpha/model"
"github.com/operator-framework/operator-registry/alpha/property"
"github.com/stretchr/testify/require"

"github.com/operator-framework/operator-registry/alpha/declcfg"
Expand Down Expand Up @@ -196,6 +198,37 @@ func TestQuerier_ListPackages(t *testing.T) {
require.Equal(t, 2, len(packages))
}

func TestQuerier_BadBundleRaisesError(t *testing.T) {
t.Helper()

// Convert a good FS into a model
cfg, err := declcfg.LoadFS(validFS)
require.NoError(t, err)

m, err := declcfg.ConvertToModel(*cfg)
require.NoError(t, err)

// break the model by adding another package property
bundle := func() *model.Bundle {
for _, pkg := range m {
for _, ch := range pkg.Channels {
for _, bundle := range ch.Bundles {
return bundle
}
}
}
return nil
}()

bundle.Properties = append(bundle.Properties, property.Property{
Type: PackageType,
Value: []byte("{\"packageName\": \"another-package\", \"version\": \"1.0.0\"}"),
})

_, err = NewQuerier(m)
require.EqualError(t, err, "parse properties: expected exactly 1 property of type \"olm.package\", found 2")
}

func genTestModelQuerier(t *testing.T) *Querier {
t.Helper()

Expand Down

0 comments on commit 716dbd1

Please sign in to comment.