Skip to content

Commit 8de87b9

Browse files
authored
Remove ginkgo from resolution/variables unit tests (#402)
Fixes #195 Signed-off-by: Todd Short <[email protected]>
1 parent 23d0386 commit 8de87b9

File tree

4 files changed

+105
-143
lines changed

4 files changed

+105
-143
lines changed
Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package variables_test
22

33
import (
4-
. "github.com/onsi/ginkgo/v2"
5-
. "github.com/onsi/gomega"
4+
"testing"
65

76
"github.com/operator-framework/deppy/pkg/deppy"
87
"github.com/operator-framework/deppy/pkg/deppy/constraint"
@@ -13,58 +12,49 @@ import (
1312
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
1413
)
1514

16-
var _ = Describe("BundleVariable", func() {
17-
var (
18-
bv *olmvariables.BundleVariable
19-
bundleEntity *olmentity.BundleEntity
20-
dependencies []*olmentity.BundleEntity
21-
)
22-
23-
BeforeEach(func() {
24-
bundleEntity = olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{
25-
property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`,
15+
func TestBundleVariable(t *testing.T) {
16+
bundleEntity := olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{
17+
property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`,
18+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
19+
}))
20+
dependencies := []*olmentity.BundleEntity{
21+
olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{
22+
property.TypePackage: `{"packageName": "test-package-2", "version": "2.0.0"}`,
23+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
24+
})),
25+
olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{
26+
property.TypePackage: `{"packageName": "test-package-3", "version": "2.0.0"}`,
2627
property.TypeChannel: `{"channelName":"stable","priority":0}`,
27-
}))
28-
dependencies = []*olmentity.BundleEntity{
29-
olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{
30-
property.TypePackage: `{"packageName": "test-package-2", "version": "2.0.0"}`,
31-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
32-
})),
33-
olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{
34-
property.TypePackage: `{"packageName": "test-package-3", "version": "2.0.0"}`,
35-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
36-
})),
28+
})),
29+
}
30+
bv := olmvariables.NewBundleVariable(bundleEntity, dependencies)
31+
32+
if bv.BundleEntity() != bundleEntity {
33+
t.Errorf("bundle entity '%v' does not match expected '%v'", bv.BundleEntity(), bundleEntity)
34+
}
35+
for i, d := range bv.Dependencies() {
36+
if d != dependencies[i] {
37+
t.Errorf("dependency[%v] '%v' does not match expected '%v'", i, d, dependencies[i])
3738
}
38-
bv = olmvariables.NewBundleVariable(bundleEntity, dependencies)
39-
})
40-
41-
It("should return the correct bundle entity", func() {
42-
Expect(bv.BundleEntity()).To(Equal(bundleEntity))
43-
})
44-
45-
It("should return the correct dependencies", func() {
46-
Expect(bv.Dependencies()).To(Equal(dependencies))
47-
})
48-
})
49-
50-
var _ = Describe("BundleUniquenessVariable", func() {
51-
var (
52-
id deppy.Identifier
53-
atMostIDs []deppy.Identifier
54-
globalConstraintVariable *olmvariables.BundleUniquenessVariable
55-
)
56-
57-
BeforeEach(func() {
58-
id = deppy.IdentifierFromString("test-id")
59-
atMostIDs = []deppy.Identifier{
60-
deppy.IdentifierFromString("test-at-most-id-1"),
61-
deppy.IdentifierFromString("test-at-most-id-2"),
39+
}
40+
}
41+
42+
func TestBundleUniquenessVariable(t *testing.T) {
43+
id := deppy.IdentifierFromString("test-id")
44+
atMostIDs := []deppy.Identifier{
45+
deppy.IdentifierFromString("test-at-most-id-1"),
46+
deppy.IdentifierFromString("test-at-most-id-2"),
47+
}
48+
globalConstraintVariable := olmvariables.NewBundleUniquenessVariable(id, atMostIDs...)
49+
50+
if globalConstraintVariable.Identifier() != id {
51+
t.Errorf("identifier '%v' does not match expected '%v'", globalConstraintVariable.Identifier(), id)
52+
}
53+
54+
constraints := []deppy.Constraint{constraint.AtMost(1, atMostIDs...)}
55+
for i, c := range globalConstraintVariable.Constraints() {
56+
if c.String("test") != constraints[i].String("test") {
57+
t.Errorf("constraint[%v] '%v' does not match expected '%v'", i, c, constraints[i])
6258
}
63-
globalConstraintVariable = olmvariables.NewBundleUniquenessVariable(id, atMostIDs...)
64-
})
65-
66-
It("should initialize a new global constraint variable", func() {
67-
Expect(globalConstraintVariable.Identifier()).To(Equal(id))
68-
Expect(globalConstraintVariable.Constraints()).To(Equal([]deppy.Constraint{constraint.AtMost(1, atMostIDs...)}))
69-
})
70-
})
59+
}
60+
}

internal/resolution/variables/installed_package_test.go

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package variables_test
22

33
import (
44
"fmt"
5-
6-
. "github.com/onsi/ginkgo/v2"
7-
. "github.com/onsi/gomega"
5+
"testing"
86

97
"github.com/operator-framework/deppy/pkg/deppy"
108
"github.com/operator-framework/deppy/pkg/deppy/input"
@@ -14,37 +12,32 @@ import (
1412
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
1513
)
1614

17-
var _ = Describe("InstalledPackageVariable", func() {
18-
var (
19-
ipv *olmvariables.InstalledPackageVariable
20-
packageName string
21-
bundleEntities []*olmentity.BundleEntity
22-
)
23-
24-
BeforeEach(func() {
25-
packageName = "test-package"
26-
bundleEntities = []*olmentity.BundleEntity{
27-
olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{
28-
property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`,
29-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
30-
})),
31-
olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{
32-
property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`,
33-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
34-
})),
35-
olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{
36-
property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`,
37-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
38-
})),
15+
func TestInstalledPackageVariable(t *testing.T) {
16+
packageName := "test-package"
17+
bundleEntities := []*olmentity.BundleEntity{
18+
olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{
19+
property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`,
20+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
21+
})),
22+
olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{
23+
property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`,
24+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
25+
})),
26+
olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{
27+
property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`,
28+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
29+
})),
30+
}
31+
ipv := olmvariables.NewInstalledPackageVariable(packageName, bundleEntities)
32+
33+
id := deppy.IdentifierFromString(fmt.Sprintf("installed package %s", packageName))
34+
if ipv.Identifier() != id {
35+
t.Errorf("package name '%v' does not match expected '%v'", ipv.Identifier(), id)
36+
}
37+
38+
for i, e := range ipv.BundleEntities() {
39+
if e != bundleEntities[i] {
40+
t.Errorf("bundle entity[%v] '%v' does not match expected '%v'", i, e, bundleEntities[i])
3941
}
40-
ipv = olmvariables.NewInstalledPackageVariable(packageName, bundleEntities)
41-
})
42-
43-
It("should return the correct package name", func() {
44-
Expect(ipv.Identifier()).To(Equal(deppy.IdentifierFromString(fmt.Sprintf("installed package %s", packageName))))
45-
})
46-
47-
It("should return the correct bundle entities", func() {
48-
Expect(ipv.BundleEntities()).To(Equal(bundleEntities))
49-
})
50-
})
42+
}
43+
}

internal/resolution/variables/required_package_test.go

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package variables_test
22

33
import (
44
"fmt"
5-
6-
. "github.com/onsi/ginkgo/v2"
7-
. "github.com/onsi/gomega"
5+
"testing"
86

97
"github.com/operator-framework/deppy/pkg/deppy"
108
"github.com/operator-framework/deppy/pkg/deppy/input"
@@ -14,42 +12,36 @@ import (
1412
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
1513
)
1614

17-
var _ = Describe("RequiredPackageVariable", func() {
18-
var (
19-
rpv *olmvariables.RequiredPackageVariable
20-
packageName string
21-
bundleEntities []*olmentity.BundleEntity
22-
)
23-
24-
BeforeEach(func() {
25-
packageName = "test-package"
26-
bundleEntities = []*olmentity.BundleEntity{
27-
olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{
28-
property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`,
29-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
30-
})),
31-
olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{
32-
property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`,
33-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
34-
})),
35-
olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{
36-
property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`,
37-
property.TypeChannel: `{"channelName":"stable","priority":0}`,
38-
})),
15+
func TestRequiredPackageVariable(t *testing.T) {
16+
packageName := "test-package"
17+
bundleEntities := []*olmentity.BundleEntity{
18+
olmentity.NewBundleEntity(input.NewEntity("bundle-1", map[string]string{
19+
property.TypePackage: `{"packageName": "test-package", "version": "1.0.0"}`,
20+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
21+
})),
22+
olmentity.NewBundleEntity(input.NewEntity("bundle-2", map[string]string{
23+
property.TypePackage: `{"packageName": "test-package", "version": "2.0.0"}`,
24+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
25+
})),
26+
olmentity.NewBundleEntity(input.NewEntity("bundle-3", map[string]string{
27+
property.TypePackage: `{"packageName": "test-package", "version": "3.0.0"}`,
28+
property.TypeChannel: `{"channelName":"stable","priority":0}`,
29+
})),
30+
}
31+
rpv := olmvariables.NewRequiredPackageVariable(packageName, bundleEntities)
32+
33+
id := deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName))
34+
if rpv.Identifier() != id {
35+
t.Errorf("package name '%v' does not match expected '%v'", rpv.Identifier(), id)
36+
}
37+
38+
for i, e := range rpv.BundleEntities() {
39+
if e != bundleEntities[i] {
40+
t.Errorf("bundle entity[%v] '%v' does not match expected '%v'", i, e, bundleEntities[i])
3941
}
40-
rpv = olmvariables.NewRequiredPackageVariable(packageName, bundleEntities)
41-
})
42-
43-
It("should return the correct package name", func() {
44-
Expect(rpv.Identifier()).To(Equal(deppy.IdentifierFromString(fmt.Sprintf("required package %s", packageName))))
45-
})
46-
47-
It("should return the correct bundle entities", func() {
48-
Expect(rpv.BundleEntities()).To(Equal(bundleEntities))
49-
})
42+
}
5043

51-
It("should contain both mandatory and dependency constraints", func() {
52-
// TODO: add this test once https://github.com/operator-framework/deppy/pull/85 gets merged
53-
// then we'll be able to inspect constraint types
54-
})
55-
})
44+
// TODO: add this test once https://github.com/operator-framework/deppy/pull/85 gets merged
45+
// then we'll be able to inspect constraint types
46+
// "should contain both mandatory and dependency constraints"
47+
}

internal/resolution/variables/variables_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)