Skip to content

Commit

Permalink
Remove ginkgo from resolution/variables unit tests (#402)
Browse files Browse the repository at this point in the history
Fixes #195

Signed-off-by: Todd Short <tshort@redhat.com>
  • Loading branch information
tmshort committed Sep 7, 2023
1 parent 23d0386 commit 8de87b9
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 143 deletions.
98 changes: 44 additions & 54 deletions internal/resolution/variables/bundle_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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...)}))
})
})
}
}
65 changes: 29 additions & 36 deletions internal/resolution/variables/installed_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
})
})
}
}
72 changes: 32 additions & 40 deletions internal/resolution/variables/required_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
13 changes: 0 additions & 13 deletions internal/resolution/variables/variables_test.go

This file was deleted.

0 comments on commit 8de87b9

Please sign in to comment.