From 33e4b839820b5c5eeda7857280051c8d041c6f7b Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Thu, 15 Jun 2023 17:24:52 +0100 Subject: [PATCH] Removes name stuttering Signed-off-by: Mikalai Radchuk --- .../bundles_and_dependencies.go | 2 +- .../variable_sources/olm/olm_test.go | 4 +-- .../requiredpackage/required_package.go | 30 +++++++++---------- .../requiredpackage/required_package_test.go | 8 ++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/internal/resolution/variable_sources/bundlesanddependencies/bundles_and_dependencies.go b/internal/resolution/variable_sources/bundlesanddependencies/bundles_and_dependencies.go index 3e3da2aa5..719e5848b 100644 --- a/internal/resolution/variable_sources/bundlesanddependencies/bundles_and_dependencies.go +++ b/internal/resolution/variable_sources/bundlesanddependencies/bundles_and_dependencies.go @@ -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()...) } } diff --git a/internal/resolution/variable_sources/olm/olm_test.go b/internal/resolution/variable_sources/olm/olm_test.go index 74183ce21..6e65d24b1 100644 --- a/internal/resolution/variable_sources/olm/olm_test.go +++ b/internal/resolution/variable_sources/olm/olm_test.go @@ -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()) diff --git a/internal/resolution/variable_sources/requiredpackage/required_package.go b/internal/resolution/variable_sources/requiredpackage/required_package.go index e66c5451a..eb9c0d5d4 100644 --- a/internal/resolution/variable_sources/requiredpackage/required_package.go +++ b/internal/resolution/variable_sources/requiredpackage/required_package.go @@ -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 { @@ -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)) @@ -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)}, } @@ -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 @@ -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 diff --git a/internal/resolution/variable_sources/requiredpackage/required_package_test.go b/internal/resolution/variable_sources/requiredpackage/required_package_test.go index 824a3eb2e..970debad8 100644 --- a/internal/resolution/variable_sources/requiredpackage/required_package_test.go +++ b/internal/resolution/variable_sources/requiredpackage/required_package_test.go @@ -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 ) @@ -62,7 +62,7 @@ var _ = Describe("RequiredPackageVariable", func() { var _ = Describe("RequiredPackageVariableSource", func() { var ( - rpvs *requiredpackage.RequiredPackageVariableSource + rpvs *requiredpackage.VariableSource packageName string mockEntitySource input.EntitySource ) @@ -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)))) @@ -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))))