diff --git a/internal/resolution/variables/bundle_test.go b/internal/resolution/variables/bundle_test.go index 506625642..85d15b762 100644 --- a/internal/resolution/variables/bundle_test.go +++ b/internal/resolution/variables/bundle_test.go @@ -1,8 +1,7 @@ package variables_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "testing" "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/constraint" @@ -13,58 +12,49 @@ import ( olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables" ) -var _ = Describe("BundleVariable", func() { - var ( - bv *olmvariables.BundleVariable - bundleEntity *olmentity.BundleEntity - dependencies []*olmentity.BundleEntity - ) - - BeforeEach(func() { - bundleEntity = olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`, +func TestBundleVariable(t *testing.T) { + bundleEntity := olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })) + dependencies := []*olmentity.BundleEntity{ + olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{ + property.TypePackage: `{"packageName": "test-package-2", "version": "2.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{ + property.TypePackage: `{"packageName": "test-package-3", "version": "2.0.0"}`, property.TypeChannel: `{"channelName":"stable","priority":0}`, - })) - dependencies = []*olmentity.BundleEntity{ - olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{ - property.TypePackage: `{"packageName": "test-package-2", "version": "2.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), - olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{ - property.TypePackage: `{"packageName": "test-package-3", "version": "2.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), + })), + } + bv := olmvariables.NewBundleVariable(bundleEntity, dependencies) + + if bv.BundleEntity() != bundleEntity { + t.Errorf("bundle entity '%v' does not match expected '%v'", bv.BundleEntity(), bundleEntity) + } + for i, d := range bv.Dependencies() { + if d != dependencies[i] { + t.Errorf("dependency[%v] '%v' does not match expected '%v'", i, d, dependencies[i]) } - bv = olmvariables.NewBundleVariable(bundleEntity, dependencies) - }) - - It("should return the correct bundle entity", func() { - Expect(bv.BundleEntity()).To(Equal(bundleEntity)) - }) - - It("should return the correct dependencies", func() { - Expect(bv.Dependencies()).To(Equal(dependencies)) - }) -}) - -var _ = Describe("BundleUniquenessVariable", func() { - var ( - id deppy.Identifier - atMostIDs []deppy.Identifier - globalConstraintVariable *olmvariables.BundleUniquenessVariable - ) - - BeforeEach(func() { - id = deppy.IdentifierFromString("test-id") - atMostIDs = []deppy.Identifier{ - deppy.IdentifierFromString("test-at-most-id-1"), - deppy.IdentifierFromString("test-at-most-id-2"), + } +} + +func TestBundleUniquenessVariable(t *testing.T) { + id := deppy.IdentifierFromString("test-id") + atMostIDs := []deppy.Identifier{ + deppy.IdentifierFromString("test-at-most-id-1"), + deppy.IdentifierFromString("test-at-most-id-2"), + } + globalConstraintVariable := olmvariables.NewBundleUniquenessVariable(id, atMostIDs...) + + if globalConstraintVariable.Identifier() != id { + t.Errorf("identifier '%v' does not match expected '%v'", globalConstraintVariable.Identifier(), id) + } + + constraints := []deppy.Constraint{constraint.AtMost(1, atMostIDs...)} + for i, c := range globalConstraintVariable.Constraints() { + if c.String("test") != constraints[i].String("test") { + t.Errorf("constraint[%v] '%v' does not match expected '%v'", i, c, constraints[i]) } - globalConstraintVariable = olmvariables.NewBundleUniquenessVariable(id, atMostIDs...) - }) - - It("should initialize a new global constraint variable", func() { - Expect(globalConstraintVariable.Identifier()).To(Equal(id)) - Expect(globalConstraintVariable.Constraints()).To(Equal([]deppy.Constraint{constraint.AtMost(1, atMostIDs...)})) - }) -}) + } +} diff --git a/internal/resolution/variables/installed_package_test.go b/internal/resolution/variables/installed_package_test.go index e725b9dbd..edcb9f5a8 100644 --- a/internal/resolution/variables/installed_package_test.go +++ b/internal/resolution/variables/installed_package_test.go @@ -2,9 +2,7 @@ package variables_test import ( "fmt" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "testing" "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/input" @@ -14,37 +12,32 @@ import ( olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables" ) -var _ = Describe("InstalledPackageVariable", func() { - var ( - ipv *olmvariables.InstalledPackageVariable - packageName string - bundleEntities []*olmentity.BundleEntity - ) - - BeforeEach(func() { - packageName = "test-package" - bundleEntities = []*olmentity.BundleEntity{ - olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), - olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), - olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), +func TestInstalledPackageVariable(t *testing.T) { + packageName := "test-package" + bundleEntities := []*olmentity.BundleEntity{ + olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + } + ipv := olmvariables.NewInstalledPackageVariable(packageName, bundleEntities) + + id := deppy.IdentifierFromString(fmt.Sprintf("installed package %s", packageName)) + if ipv.Identifier() != id { + t.Errorf("package name '%v' does not match expected '%v'", ipv.Identifier(), id) + } + + for i, e := range ipv.BundleEntities() { + if e != bundleEntities[i] { + t.Errorf("bundle entity[%v] '%v' does not match expected '%v'", i, e, bundleEntities[i]) } - ipv = olmvariables.NewInstalledPackageVariable(packageName, bundleEntities) - }) - - It("should return the correct package name", func() { - Expect(ipv.Identifier()).To(Equal(deppy.IdentifierFromString(fmt.Sprintf("installed package %s", packageName)))) - }) - - It("should return the correct bundle entities", func() { - Expect(ipv.BundleEntities()).To(Equal(bundleEntities)) - }) -}) + } +} diff --git a/internal/resolution/variables/required_package_test.go b/internal/resolution/variables/required_package_test.go index 3065ba81a..a0872fa6f 100644 --- a/internal/resolution/variables/required_package_test.go +++ b/internal/resolution/variables/required_package_test.go @@ -2,9 +2,7 @@ package variables_test import ( "fmt" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "testing" "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/input" @@ -14,42 +12,36 @@ import ( olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables" ) -var _ = Describe("RequiredPackageVariable", func() { - var ( - rpv *olmvariables.RequiredPackageVariable - packageName string - bundleEntities []*olmentity.BundleEntity - ) - - BeforeEach(func() { - packageName = "test-package" - bundleEntities = []*olmentity.BundleEntity{ - olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), - olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), - olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{ - property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`, - property.TypeChannel: `{"channelName":"stable","priority":0}`, - })), +func TestRequiredPackageVariable(t *testing.T) { + packageName := "test-package" + bundleEntities := []*olmentity.BundleEntity{ + olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{ + property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`, + property.TypeChannel: `{"channelName":"stable","priority":0}`, + })), + } + rpv := olmvariables.NewRequiredPackageVariable(packageName, bundleEntities) + + id := deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName)) + if rpv.Identifier() != id { + t.Errorf("package name '%v' does not match expected '%v'", rpv.Identifier(), id) + } + + for i, e := range rpv.BundleEntities() { + if e != bundleEntities[i] { + t.Errorf("bundle entity[%v] '%v' does not match expected '%v'", i, e, bundleEntities[i]) } - rpv = olmvariables.NewRequiredPackageVariable(packageName, bundleEntities) - }) - - It("should return the correct package name", func() { - Expect(rpv.Identifier()).To(Equal(deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName)))) - }) - - It("should return the correct bundle entities", func() { - Expect(rpv.BundleEntities()).To(Equal(bundleEntities)) - }) + } - It("should contain both mandatory and dependency constraints", func() { - // TODO: add this test once https://github.com/operator-framework/deppy/pull/85 gets merged - // then we'll be able to inspect constraint types - }) -}) + // TODO: add this test once https://github.com/operator-framework/deppy/pull/85 gets merged + // then we'll be able to inspect constraint types + // "should contain both mandatory and dependency constraints" +} diff --git a/internal/resolution/variables/variables_test.go b/internal/resolution/variables/variables_test.go deleted file mode 100644 index e1b7a553d..000000000 --- a/internal/resolution/variables/variables_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package variables_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestVariableSources(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Variables Suite") -}