Skip to content

Commit

Permalink
Removes name stuttering
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Jun 20, 2023
1 parent c41b117 commit 73646a5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context, entityS
var bundleEntityQueue []*olmentity.BundleEntity
for _, variable := range variables {
switch v := variable.(type) {
case *requiredpackage.RequiredPackageVariable:
case *requiredpackage.Variable:
bundleEntityQueue = append(bundleEntityQueue, v.BundleEntities()...)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/resolution/variable_sources/olm/olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ var _ = Describe("OLMVariableSource", func() {
variables, err := olmVariableSource.GetVariables(context.Background(), testEntitySource)
Expect(err).ToNot(HaveOccurred())

packageRequiredVariables := filterVariables[*requiredpackage.RequiredPackageVariable](variables)
packageRequiredVariables := filterVariables[*requiredpackage.Variable](variables)
Expect(packageRequiredVariables).To(HaveLen(2))
Expect(packageRequiredVariables).To(WithTransform(func(bvars []*requiredpackage.RequiredPackageVariable) map[deppy.Identifier]int {
Expect(packageRequiredVariables).To(WithTransform(func(bvars []*requiredpackage.Variable) map[deppy.Identifier]int {
out := map[deppy.Identifier]int{}
for _, variable := range bvars {
out[variable.Identifier()] = len(variable.BundleEntities())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ import (
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/util/sort"
)

type RequiredPackageVariable struct {
type Variable struct {
*input.SimpleVariable
bundleEntities []*olmentity.BundleEntity
}

func (r *RequiredPackageVariable) BundleEntities() []*olmentity.BundleEntity {
func (r *Variable) BundleEntities() []*olmentity.BundleEntity {
return r.bundleEntities
}

func NewRequiredPackageVariable(packageName string, bundleEntities []*olmentity.BundleEntity) *RequiredPackageVariable {
func NewRequiredPackageVariable(packageName string, bundleEntities []*olmentity.BundleEntity) *Variable {
id := deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName))
entityIDs := make([]deppy.Identifier, 0, len(bundleEntities))
for _, bundle := range bundleEntities {
entityIDs = append(entityIDs, bundle.ID)
}
return &RequiredPackageVariable{
return &Variable{
SimpleVariable: input.NewSimpleVariable(id, constraint.Mandatory(), constraint.Dependency(entityIDs...)),
bundleEntities: bundleEntities,
}
}

var _ input.VariableSource = &RequiredPackageVariableSource{}
var _ input.VariableSource = &VariableSource{}

type RequiredPackageOption func(*RequiredPackageVariableSource) error
type Option func(*VariableSource) error

func InVersionRange(versionRange string) RequiredPackageOption {
return func(r *RequiredPackageVariableSource) error {
func InVersionRange(versionRange string) Option {
return func(r *VariableSource) error {
if versionRange != "" {
vr, err := semver.ParseRange(versionRange)
if err == nil {
Expand All @@ -55,8 +55,8 @@ func InVersionRange(versionRange string) RequiredPackageOption {
}
}

func InChannel(channelName string) RequiredPackageOption {
return func(r *RequiredPackageVariableSource) error {
func InChannel(channelName string) Option {
return func(r *VariableSource) error {
if channelName != "" {
r.channelName = channelName
r.predicates = append(r.predicates, predicates.InChannel(channelName))
Expand All @@ -65,18 +65,18 @@ func InChannel(channelName string) RequiredPackageOption {
}
}

type RequiredPackageVariableSource struct {
type VariableSource struct {
packageName string
versionRange string
channelName string
predicates []input.Predicate
}

func NewRequiredPackage(packageName string, options ...RequiredPackageOption) (*RequiredPackageVariableSource, error) {
func NewRequiredPackage(packageName string, options ...Option) (*VariableSource, error) {
if packageName == "" {
return nil, fmt.Errorf("package name must not be empty")
}
r := &RequiredPackageVariableSource{
r := &VariableSource{
packageName: packageName,
predicates: []input.Predicate{predicates.WithPackageName(packageName)},
}
Expand All @@ -88,7 +88,7 @@ func NewRequiredPackage(packageName string, options ...RequiredPackageOption) (*
return r, nil
}

func (r *RequiredPackageVariableSource) GetVariables(ctx context.Context, entitySource input.EntitySource) ([]deppy.Variable, error) {
func (r *VariableSource) GetVariables(ctx context.Context, entitySource input.EntitySource) ([]deppy.Variable, error) {
resultSet, err := entitySource.Filter(ctx, input.And(r.predicates...))
if err != nil {
return nil, err
Expand All @@ -106,7 +106,7 @@ func (r *RequiredPackageVariableSource) GetVariables(ctx context.Context, entity
}, nil
}

func (r *RequiredPackageVariableSource) notFoundError() error {
func (r *VariableSource) notFoundError() error {
// TODO: update this error message when/if we decide to support version ranges as opposed to fixing the version
// context: we originally wanted to support version ranges and take the highest version that satisfies the range
// during the upstream call on the 2023-04-11 we decided to pin the version instead. But, we'll keep version range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestRequiredPackage(t *testing.T) {

var _ = Describe("RequiredPackageVariable", func() {
var (
rpv *requiredpackage.RequiredPackageVariable
rpv *requiredpackage.Variable
packageName string
bundleEntities []*olmentity.BundleEntity
)
Expand Down Expand Up @@ -62,7 +62,7 @@ var _ = Describe("RequiredPackageVariable", func() {

var _ = Describe("RequiredPackageVariableSource", func() {
var (
rpvs *requiredpackage.RequiredPackageVariableSource
rpvs *requiredpackage.VariableSource
packageName string
mockEntitySource input.EntitySource
)
Expand Down Expand Up @@ -102,7 +102,7 @@ var _ = Describe("RequiredPackageVariableSource", func() {
variables, err := rpvs.GetVariables(context.TODO(), mockEntitySource)
Expect(err).NotTo(HaveOccurred())
Expect(variables).To(HaveLen(1))
reqPackageVar, ok := variables[0].(*requiredpackage.RequiredPackageVariable)
reqPackageVar, ok := variables[0].(*requiredpackage.Variable)
Expect(ok).To(BeTrue())
Expect(reqPackageVar.Identifier()).To(Equal(deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName))))

Expand Down Expand Up @@ -131,7 +131,7 @@ var _ = Describe("RequiredPackageVariableSource", func() {
variables, err := rpvs.GetVariables(context.TODO(), mockEntitySource)
Expect(err).NotTo(HaveOccurred())
Expect(variables).To(HaveLen(1))
reqPackageVar, ok := variables[0].(*requiredpackage.RequiredPackageVariable)
reqPackageVar, ok := variables[0].(*requiredpackage.Variable)
Expect(ok).To(BeTrue())
Expect(reqPackageVar.Identifier()).To(Equal(deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName))))

Expand Down

0 comments on commit 73646a5

Please sign in to comment.