Skip to content

Commit 459fab3

Browse files
author
Per Goncalves da Silva
committed
Refactor MakeCSV utility to builder pattern
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent fbd2e65 commit 459fab3

File tree

12 files changed

+568
-631
lines changed

12 files changed

+568
-631
lines changed

internal/operator-controller/applier/boxcutter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232
"github.com/operator-framework/operator-controller/internal/operator-controller/labels"
3333
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
3434
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
35-
testutils "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing"
3635
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/bundlefs"
36+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion"
3737
)
3838

3939
func Test_RegistryV1BundleRenderer_Render_Success(t *testing.T) {
@@ -57,8 +57,8 @@ func Test_RegistryV1BundleRenderer_Render_Success(t *testing.T) {
5757
}
5858
bundleFS := bundlefs.Builder().
5959
WithPackageName("some-package").
60-
WithCSV(testutils.MakeCSV(testutils.WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces))).Build()
61-
60+
WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build()).
61+
Build()
6262
objs, err := r.Render(bundleFS, &ocv1.ClusterExtension{
6363
Spec: ocv1.ClusterExtensionSpec{
6464
Namespace: "some-namespace",
@@ -81,8 +81,8 @@ func Test_RegistryV1BundleRenderer_Render_Failure(t *testing.T) {
8181
}
8282
bundleFS := bundlefs.Builder().
8383
WithPackageName("some-package").
84-
WithCSV(testutils.MakeCSV(testutils.WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces))).Build()
85-
84+
WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build()).
85+
Build()
8686
objs, err := r.Render(bundleFS, &ocv1.ClusterExtension{
8787
Spec: ocv1.ClusterExtensionSpec{
8888
Namespace: "some-namespace",
@@ -811,7 +811,7 @@ func TestBoxcutter_Apply(t *testing.T) {
811811
} else {
812812
require.NoError(t, err)
813813
assert.False(t, installSucceeded)
814-
assert.Equal(t, "New revision created", installStatus)
814+
assert.Equal(t, "Builder revision created", installStatus)
815815
}
816816

817817
if tc.validate != nil {

internal/operator-controller/applier/provider_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
2222
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
2323
. "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing"
24+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion"
2425
)
2526

2627
func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleSourceFailures(t *testing.T) {
@@ -51,7 +52,7 @@ func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleRendererFailures(t *testi
5152

5253
b := source.FromBundle(
5354
bundle.RegistryV1{
54-
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)),
55+
CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(),
5556
},
5657
)
5758

@@ -70,7 +71,7 @@ func Test_RegistryV1HelmChartProvider_Get_NoAPIServiceDefinitions(t *testing.T)
7071

7172
b := source.FromBundle(
7273
bundle.RegistryV1{
73-
CSV: MakeCSV(WithOwnedAPIServiceDescriptions(v1alpha1.APIServiceDescription{})),
74+
CSV: clusterserviceversion.Builder().WithOwnedAPIServiceDescriptions(v1alpha1.APIServiceDescription{}).Build(),
7475
},
7576
)
7677

@@ -91,7 +92,7 @@ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace(t *testing.T) {
9192

9293
b := source.FromBundle(
9394
bundle.RegistryV1{
94-
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace)),
95+
CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build(),
9596
},
9697
)
9798

@@ -114,7 +115,7 @@ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace(t *testing.T) {
114115

115116
b := source.FromBundle(
116117
bundle.RegistryV1{
117-
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace)),
118+
CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).Build(),
118119
},
119120
)
120121

@@ -142,7 +143,7 @@ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace(t *testing.T) {
142143

143144
b := source.FromBundle(
144145
bundle.RegistryV1{
145-
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace)),
146+
CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build(),
146147
},
147148
)
148149

@@ -164,7 +165,7 @@ func Test_RegistryV1HelmChartProvider_Get_NoWebhooksWithoutCertProvider(t *testi
164165

165166
b := source.FromBundle(
166167
bundle.RegistryV1{
167-
CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})),
168+
CSV: clusterserviceversion.Builder().WithWebhookDefinitions(v1alpha1.WebhookDescription{}).Build(),
168169
},
169170
)
170171

@@ -186,7 +187,7 @@ func Test_RegistryV1HelmChartProvider_Get_WebhooksSupportDisabled(t *testing.T)
186187

187188
b := source.FromBundle(
188189
bundle.RegistryV1{
189-
CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})),
190+
CSV: clusterserviceversion.Builder().WithWebhookDefinitions(v1alpha1.WebhookDescription{}).Build(),
190191
},
191192
)
192193

@@ -209,10 +210,9 @@ func Test_RegistryV1HelmChartProvider_Get_WebhooksWithCertProvider(t *testing.T)
209210

210211
b := source.FromBundle(
211212
bundle.RegistryV1{
212-
CSV: MakeCSV(
213-
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
214-
WithWebhookDefinitions(v1alpha1.WebhookDescription{}),
215-
),
213+
CSV: clusterserviceversion.Builder().
214+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).
215+
WithWebhookDefinitions(v1alpha1.WebhookDescription{}).Build(),
216216
},
217217
)
218218

@@ -245,7 +245,7 @@ func Test_RegistryV1HelmChartProvider_Get_BundleRendererIntegration(t *testing.T
245245

246246
b := source.FromBundle(
247247
bundle.RegistryV1{
248-
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace)),
248+
CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace).Build(),
249249
},
250250
)
251251

@@ -315,10 +315,9 @@ func Test_RegistryV1HelmChartProvider_Get_Success(t *testing.T) {
315315

316316
b := source.FromBundle(
317317
bundle.RegistryV1{
318-
CSV: MakeCSV(
319-
WithAnnotations(map[string]string{"foo": "bar"}),
320-
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
321-
),
318+
CSV: clusterserviceversion.Builder().
319+
WithAnnotations(map[string]string{"foo": "bar"}).
320+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(),
322321
Others: []unstructured.Unstructured{
323322
*ToUnstructuredT(t, &corev1.Service{
324323
TypeMeta: metav1.TypeMeta{

internal/operator-controller/rukpak/bundle/source/source_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
1515
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
16-
testutils "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing"
1716
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/bundlefs"
17+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion"
1818
)
1919

2020
const (
@@ -34,13 +34,13 @@ func Test_FromFS_Success(t *testing.T) {
3434
bundleFS := bundlefs.Builder().
3535
WithPackageName("test").
3636
WithBundleProperty("from-file-key", "from-file-value").
37-
WithBundleResource("csv.yaml", ptr.To(testutils.MakeCSV(
38-
testutils.WithName("test.v1.0.0"),
39-
testutils.WithAnnotations(map[string]string{
37+
WithBundleResource("csv.yaml", ptr.To(clusterserviceversion.Builder().
38+
WithName("test.v1.0.0").
39+
WithAnnotations(map[string]string{
4040
"olm.properties": `[{"type":"from-csv-annotations-key", "value":"from-csv-annotations-value"}]`,
41-
}),
42-
testutils.WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)),
43-
)).Build()
41+
}).
42+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build())).
43+
Build()
4444

4545
rv1, err := source.FromFS(bundleFS).GetBundle()
4646
require.NoError(t, err)
@@ -72,12 +72,12 @@ func Test_FromFS_Fails(t *testing.T) {
7272
name: "bundle missing metadata/annotations.yaml",
7373
FS: bundlefs.Builder().
7474
WithBundleProperty("foo", "bar").
75-
WithBundleResource("csv.yaml", ptr.To(testutils.MakeCSV())).Build(),
75+
WithBundleResource("csv.yaml", ptr.To(clusterserviceversion.Builder().Build())).Build(),
7676
}, {
7777
name: "metadata/annotations.yaml missing package name annotation",
7878
FS: bundlefs.Builder().
7979
WithBundleProperty("foo", "bar").
80-
WithBundleResource("csv.yaml", ptr.To(testutils.MakeCSV())).Build(),
80+
WithBundleResource("csv.yaml", ptr.To(clusterserviceversion.Builder().Build())).Build(),
8181
}, {
8282
name: "bundle missing manifests directory",
8383
FS: bundlefs.Builder().

0 commit comments

Comments
 (0)