Skip to content

Commit 144cbd6

Browse files
committed
Replace gingko test with go testing - review comments addressed
Signed-off-by: jubittajohn <[email protected]>
1 parent ec7e28c commit 144cbd6

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

internal/resolution/resolver_test.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/stretchr/testify/assert"
98
"github.com/operator-framework/deppy/pkg/deppy"
109
"github.com/operator-framework/deppy/pkg/deppy/input"
10+
"github.com/stretchr/testify/assert"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/runtime"
1313
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -19,28 +19,28 @@ import (
1919

2020
func TestOperatorResolver(t *testing.T) {
2121

22-
testEntityCache := map[deppy.Identifier]input.Entity{ "operatorhub/prometheus/0.37.0": *input.NewEntity("operatorhub/prometheus/0.37.0" , map[string]string{
23-
"olm.bundle.path": `"quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35"`,
24-
"olm.channel": "{\"channelName\":\"beta\",\"priority\":0,\"replaces\":\"prometheusoperator.0.32.0\"}",
25-
"olm.gvk": "[{\"group\":\"monitoring.coreos.com\",\"kind\":\"Alertmanager\",\"version\":\"v1\"}, {\"group\":\"monitoring.coreos.com\",\"kind\":\"Prometheus\",\"version\":\"v1\"}]",
26-
"olm.package": "{\"packageName\":\"prometheus\",\"version\":\"0.37.0\"}",
27-
}),
22+
testEntityCache := map[deppy.Identifier]input.Entity{"operatorhub/prometheus/0.37.0": *input.NewEntity("operatorhub/prometheus/0.37.0", map[string]string{
23+
"olm.bundle.path": `"quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35"`,
24+
"olm.channel": "{\"channelName\":\"beta\",\"priority\":0,\"replaces\":\"prometheusoperator.0.32.0\"}",
25+
"olm.gvk": "[{\"group\":\"monitoring.coreos.com\",\"kind\":\"Alertmanager\",\"version\":\"v1\"}, {\"group\":\"monitoring.coreos.com\",\"kind\":\"Prometheus\",\"version\":\"v1\"}]",
26+
"olm.package": "{\"packageName\":\"prometheus\",\"version\":\"0.37.0\"}",
27+
}),
2828
"operatorhub/prometheus/0.47.0": *input.NewEntity("operatorhub/prometheus/0.47.0", map[string]string{
2929
"olm.bundle.path": `"quay.io/operatorhubio/prometheus@sha256:5b04c49d8d3eff6a338b56ec90bdf491d501fe301c9cdfb740e5bff6769a21ed"`,
3030
"olm.channel": "{\"channelName\":\"beta\",\"priority\":0,\"replaces\":\"prometheusoperator.0.37.0\"}",
3131
"olm.gvk": "[{\"group\":\"monitoring.coreos.com\",\"kind\":\"Alertmanager\",\"version\":\"v1\"}, {\"group\":\"monitoring.coreos.com\",\"kind\":\"Prometheus\",\"version\":\"v1alpha1\"}]",
3232
"olm.package": "{\"packageName\":\"prometheus\",\"version\":\"0.47.0\"}",
33-
}),
33+
}),
3434
"operatorhub/packageA/2.0.0": *input.NewEntity("operatorhub/packageA/2.0.0", map[string]string{
3535
"olm.bundle.path": `"foo.io/packageA/packageA:v2.0.0"`,
3636
"olm.channel": "{\"channelName\":\"stable\",\"priority\":0}",
3737
"olm.gvk": "[{\"group\":\"foo.io\",\"kind\":\"Foo\",\"version\":\"v1\"}]",
3838
"olm.package": "{\"packageName\":\"packageA\",\"version\":\"2.0.0\"}",
39-
}),
39+
}),
4040
}
4141
testEntitySource := input.NewCacheQuerier(testEntityCache)
4242

43-
testResource := []client.Object{
43+
testResource := []client.Object{
4444
&v1alpha1.Operator{
4545
ObjectMeta: metav1.ObjectMeta{
4646
Name: "prometheus",
@@ -58,48 +58,46 @@ func TestOperatorResolver(t *testing.T) {
5858
},
5959
},
6060
}
61-
62-
errorClient := NewFailClientWithError(fmt.Errorf("something bad happened"))
6361

6462
for _, tt := range []struct {
65-
Name string
66-
Client client.Client
67-
EntitySource input.EntitySource
68-
SelectedVariableCnt int
69-
ExpectedError error
70-
}{
63+
Name string
64+
Client client.Client
65+
EntitySource input.EntitySource
66+
SelectedVariableCnt int
67+
ExpectedError error
68+
}{
7169
{
72-
Name: "should resolve the packages described by the available Operator resources",
73-
Client: FakeClient(testResource...),
74-
EntitySource: testEntitySource,
70+
Name: "should resolve the packages described by the available Operator resources",
71+
Client: FakeClient(testResource...),
72+
EntitySource: testEntitySource,
7573
SelectedVariableCnt: 4,
76-
ExpectedError: nil,
74+
ExpectedError: nil,
7775
},
7876
{
79-
Name: "should not return an error if there are no Operator resources",
80-
Client: FakeClient([]client.Object{}...),
81-
EntitySource: testEntitySource,
77+
Name: "should not return an error if there are no Operator resources",
78+
Client: FakeClient(),
79+
EntitySource: testEntitySource,
8280
SelectedVariableCnt: 0,
83-
ExpectedError: nil,
81+
ExpectedError: nil,
8482
},
8583
{
86-
Name: "should return an error if the entity source throws an error",
87-
Client: FakeClient(testResource...),
88-
EntitySource: FailEntitySource{},
84+
Name: "should return an error if the entity source throws an error",
85+
Client: FakeClient(testResource...),
86+
EntitySource: FailEntitySource{},
8987
ExpectedError: fmt.Errorf("error calling filter in entity source"),
90-
},
88+
},
9189
{
92-
Name: "should return an error if the client throws an error",
93-
Client: errorClient,
94-
EntitySource: testEntitySource,
90+
Name: "should return an error if the client throws an error",
91+
Client: NewFailClientWithError(fmt.Errorf("something bad happened")),
92+
EntitySource: testEntitySource,
9593
ExpectedError: fmt.Errorf("something bad happened"),
96-
},
94+
},
9795
} {
98-
t.Run(tt.Name, func(t *testing.T) {
99-
client := tt.Client
100-
entitySource := tt.EntitySource
96+
t.Run(tt.Name, func(t *testing.T) {
97+
client := tt.Client
98+
entitySource := tt.EntitySource
10199
resolver := resolution.NewOperatorResolver(client, entitySource)
102-
solution, err := resolver.Resolve(context.Background())
100+
solution, err := resolver.Resolve(context.Background())
103101

104102
if err != nil {
105103
assert.Equal(t, err, tt.ExpectedError)

0 commit comments

Comments
 (0)