Skip to content

Commit 455ad13

Browse files
committed
fixing unit tests
1 parent 63d6e93 commit 455ad13

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed

controllers/catalogsource_controller_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ var _ = Describe("CatalogSource Controller Test", func() {
141141
By("running re-reconcile")
142142
res, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: opKey})
143143
Expect(res).To(Equal(ctrl.Result{}))
144+
Expect(err).ToNot(HaveOccurred())
144145

145146
By("checking the cache is empty again")
146147
entities = nil
@@ -151,5 +152,63 @@ var _ = Describe("CatalogSource Controller Test", func() {
151152
Expect(err).ToNot(HaveOccurred())
152153
Expect(entities).To(BeEmpty())
153154
})
155+
156+
Describe("querying CatalogSource EntitySource", func() {
157+
BeforeEach(func() {
158+
registryEntities := []*input.Entity{
159+
input.NewEntity(deppy.Identifier(fmt.Sprintf("%s/%s/pkg1/chan1/0.1.0", catalogSourceName, namespace)), map[string]string{}),
160+
input.NewEntity(deppy.Identifier(fmt.Sprintf("%s/%s/pkg1/chan1/0.2.0", catalogSourceName, namespace)), map[string]string{"k": "v"}),
161+
}
162+
fakeRegistry.setEntitiesForSource(opKey.String(), registryEntities...)
163+
164+
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: opKey})
165+
Expect(err).ToNot(HaveOccurred())
166+
Expect(res).To(Equal(ctrl.Result{}))
167+
})
168+
Describe("Get", func() {
169+
It("should fetch an entity by ID", func() {
170+
Expect(reconciler.Get(ctx, deppy.Identifier(fmt.Sprintf("%s/%s/pkg1/chan1/0.1.0", catalogSourceName, namespace)))).To(
171+
Equal(input.NewEntity(deppy.Identifier(fmt.Sprintf("%s/%s/pkg1/chan1/0.1.0", catalogSourceName, namespace)), map[string]string{})),
172+
)
173+
})
174+
It("should not fetch anything for nonexistent entity ID", func() {
175+
Expect(reconciler.Get(ctx, "non-existent")).To(BeNil())
176+
})
177+
})
178+
Describe("Filter", func() {
179+
It("should return entities that meet filter predicates", func() {
180+
actual, err := reconciler.Filter(ctx, func(e *input.Entity) bool {
181+
_, ok := e.Properties["k"]
182+
return ok
183+
})
184+
Expect(err).ToNot(HaveOccurred())
185+
Expect(actual).To(ConsistOf(input.EntityList{*input.NewEntity(deppy.Identifier(fmt.Sprintf("%s/%s/pkg1/chan1/0.2.0", catalogSourceName, namespace)), map[string]string{"k": "v"})}))
186+
})
187+
})
188+
Describe("GroupBy", func() {
189+
It("should group entities by the keys provided by the groupBy function", func() {
190+
actual, err := reconciler.GroupBy(ctx, func(e *input.Entity) []string {
191+
var keys []string
192+
for k := range e.Properties {
193+
keys = append(keys, k)
194+
}
195+
return keys
196+
})
197+
Expect(err).ToNot(HaveOccurred())
198+
Expect(actual).To(Equal(input.EntityListMap{"k": input.EntityList{*input.NewEntity(deppy.Identifier(fmt.Sprintf("%s/%s/pkg1/chan1/0.2.0", catalogSourceName, namespace)), map[string]string{"k": "v"})}}))
199+
})
200+
})
201+
Describe("Iterate", func() {
202+
It("should go through all entities", func() {
203+
var ids []string
204+
Expect(reconciler.Iterate(ctx, func(e *input.Entity) error {
205+
ids = append(ids, e.Identifier().String())
206+
return nil
207+
})).To(BeNil())
208+
Expect(ids).To(ConsistOf([]string{fmt.Sprintf("%s/%s/pkg1/chan1/0.1.0", catalogSourceName, namespace),
209+
fmt.Sprintf("%s/%s/pkg1/chan1/0.2.0", catalogSourceName, namespace)}))
210+
})
211+
})
212+
})
154213
})
155214
})

controllers/operator_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ var testEntitySource = input.NewCacheQuerier(map[deppy.Identifier]input.Entity{
570570
"olm.gvk": `[]`,
571571
}),
572572
"operatorhub/badimage/0.1.0": *input.NewEntity("operatorhub/badimage/0.1.0", map[string]string{
573-
"olm.bundle.path": `{"name": "quay.io/operatorhubio/badimage:v0.1.0"}`,
573+
"olm.bundle.path": ``,
574574
"olm.package": `{"packageName":"badimage","version":"0.1.0"}`,
575575
"olm.gvk": `[]`,
576576
}),

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
github.com/blang/semver/v4 v4.0.0
7+
github.com/containerd/containerd v1.6.3
78
github.com/onsi/ginkgo/v2 v2.3.1
89
github.com/onsi/gomega v1.22.1
910
github.com/operator-framework/api v0.15.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
9898
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
9999
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
100100
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
101+
github.com/containerd/containerd v1.6.3 h1:JfgUEIAH07xDWk6kqz0P3ArZt+KJ9YeihSC9uyFtSKg=
102+
github.com/containerd/containerd v1.6.3/go.mod h1:gCVGrYRYFm2E8GmuUIbj/NGD7DLZQLzSJQazjVKDOig=
101103
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
102104
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
103105
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

internal/resolution/variable_sources/olm/olm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55

66
"github.com/operator-framework/deppy/pkg/deppy"
77
"github.com/operator-framework/deppy/pkg/deppy/input"
8-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/required_package"
98

109
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies"
1110
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/crd_constraints"
11+
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/required_package"
1212
)
1313

1414
var _ input.VariableSource = &OLMVariableSource{}

internal/resolution/variable_sources/required_package/required_package_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
. "github.com/onsi/gomega"
1010
"github.com/operator-framework/deppy/pkg/deppy"
1111
"github.com/operator-framework/deppy/pkg/deppy/input"
12-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/required_package"
1312
"github.com/operator-framework/operator-registry/alpha/property"
1413

1514
olmentity "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
15+
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/required_package"
1616
)
1717

1818
func TestRequiredPackage(t *testing.T) {

0 commit comments

Comments
 (0)