Skip to content

Commit 7e321b4

Browse files
authored
Update installed package unit tests (#524)
This commit does two things. First: It splits the `TestMakeInstalledPackageVariables` test into two tests: * One for when `ForceSemverUpgradeConstraints` feature gate enabled (semver) * One for when `ForceSemverUpgradeConstraints` feature gate disabled (legacy semantics) Both tests are now table-style tests. This is done mainly so that we can maintain test data for different semantics separately (e.g. no need to maintain channel entires for semver tests). Second: Adds extra coverage for disabled state of the `ForceSemverUpgradeConstraints` feature gate. Previously we were not covering some cases for this state of the gate. Example of such case is when `UpgradeConstraintPolicy` field on `Operator` is set to `Ignore`. Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
1 parent 3373785 commit 7e321b4

File tree

3 files changed

+437
-383
lines changed

3 files changed

+437
-383
lines changed

internal/resolution/variablesources/bundle_deployment_test.go

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,10 @@ import (
1515
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
1616
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
1717

18-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19-
"k8s.io/apimachinery/pkg/util/uuid"
20-
"k8s.io/utils/pointer"
21-
2218
"github.com/operator-framework/deppy/pkg/deppy"
2319
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
2420
)
2521

26-
func fakeOperator(name, packageName string, upgradeConstraintPolicy operatorsv1alpha1.UpgradeConstraintPolicy) operatorsv1alpha1.Operator {
27-
return operatorsv1alpha1.Operator{
28-
ObjectMeta: metav1.ObjectMeta{
29-
Name: name,
30-
// We manually set a fake UID here because the code we test
31-
// uses UID to determine Operator CR which
32-
// owns `BundleDeployment`
33-
UID: uuid.NewUUID(),
34-
},
35-
Spec: operatorsv1alpha1.OperatorSpec{
36-
PackageName: packageName,
37-
UpgradeConstraintPolicy: upgradeConstraintPolicy,
38-
},
39-
}
40-
}
41-
42-
func bundleDeployment(name, image string, owner *operatorsv1alpha1.Operator) rukpakv1alpha1.BundleDeployment {
43-
bd := rukpakv1alpha1.BundleDeployment{
44-
ObjectMeta: metav1.ObjectMeta{
45-
Name: name,
46-
},
47-
Spec: rukpakv1alpha1.BundleDeploymentSpec{
48-
ProvisionerClassName: "core-rukpak-io-plain",
49-
Template: &rukpakv1alpha1.BundleTemplate{
50-
Spec: rukpakv1alpha1.BundleSpec{
51-
ProvisionerClassName: "core-rukpak-io-plain",
52-
Source: rukpakv1alpha1.BundleSource{
53-
Image: &rukpakv1alpha1.ImageSource{
54-
Ref: image,
55-
},
56-
},
57-
},
58-
},
59-
},
60-
}
61-
62-
if owner != nil {
63-
bd.SetOwnerReferences([]metav1.OwnerReference{
64-
{
65-
APIVersion: operatorsv1alpha1.GroupVersion.String(),
66-
Kind: "Operator",
67-
Name: owner.Name,
68-
UID: owner.UID,
69-
Controller: pointer.Bool(true),
70-
BlockOwnerDeletion: pointer.Bool(true),
71-
},
72-
})
73-
}
74-
75-
return bd
76-
}
77-
7822
var _ = Describe("BundleDeploymentVariableSource", func() {
7923
var betaChannel catalogmetadata.Channel
8024
var stableChannel catalogmetadata.Channel
@@ -139,7 +83,7 @@ var _ = Describe("BundleDeploymentVariableSource", func() {
13983
fakeOperator := fakeOperator("test-operator", "prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
14084
operators := []operatorsv1alpha1.Operator{fakeOperator}
14185
bundleDeployments := []rukpakv1alpha1.BundleDeployment{
142-
bundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35", &fakeOperator),
86+
fakeBundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35", &fakeOperator),
14387
}
14488

14589
bdVariableSource := variablesources.NewBundleDeploymentVariableSource(operators, bundleDeployments, testBundleList, &MockRequiredPackageSource{})
@@ -164,7 +108,7 @@ var _ = Describe("BundleDeploymentVariableSource", func() {
164108
fakeOperator := fakeOperator("test-operator", "prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
165109
operators := []operatorsv1alpha1.Operator{fakeOperator}
166110
bundleDeployments := []rukpakv1alpha1.BundleDeployment{
167-
bundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:nonexistent", &fakeOperator),
111+
fakeBundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:nonexistent", &fakeOperator),
168112
}
169113

170114
bdVariableSource := variablesources.NewBundleDeploymentVariableSource(operators, bundleDeployments, testBundleList, &MockRequiredPackageSource{})
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package variablesources_test
2+
3+
import (
4+
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
"k8s.io/apimachinery/pkg/util/uuid"
8+
"k8s.io/utils/pointer"
9+
10+
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
11+
)
12+
13+
func fakeOperator(name, packageName string, upgradeConstraintPolicy operatorsv1alpha1.UpgradeConstraintPolicy) operatorsv1alpha1.Operator {
14+
return operatorsv1alpha1.Operator{
15+
ObjectMeta: metav1.ObjectMeta{
16+
Name: name,
17+
// We manually set a fake UID here because the code we test
18+
// uses UID to determine Operator CR which
19+
// owns `BundleDeployment`
20+
UID: uuid.NewUUID(),
21+
},
22+
Spec: operatorsv1alpha1.OperatorSpec{
23+
PackageName: packageName,
24+
UpgradeConstraintPolicy: upgradeConstraintPolicy,
25+
},
26+
}
27+
}
28+
29+
func fakeBundleDeployment(name, bundleImage string, owner *operatorsv1alpha1.Operator) rukpakv1alpha1.BundleDeployment {
30+
bd := rukpakv1alpha1.BundleDeployment{
31+
ObjectMeta: metav1.ObjectMeta{
32+
Name: name,
33+
},
34+
Spec: rukpakv1alpha1.BundleDeploymentSpec{
35+
ProvisionerClassName: "core-rukpak-io-plain",
36+
Template: &rukpakv1alpha1.BundleTemplate{
37+
Spec: rukpakv1alpha1.BundleSpec{
38+
ProvisionerClassName: "core-rukpak-io-plain",
39+
Source: rukpakv1alpha1.BundleSource{
40+
Image: &rukpakv1alpha1.ImageSource{
41+
Ref: bundleImage,
42+
},
43+
},
44+
},
45+
},
46+
},
47+
}
48+
49+
if owner != nil {
50+
bd.SetOwnerReferences([]metav1.OwnerReference{
51+
{
52+
APIVersion: operatorsv1alpha1.GroupVersion.String(),
53+
Kind: "Operator",
54+
Name: owner.Name,
55+
UID: owner.UID,
56+
Controller: pointer.Bool(true),
57+
BlockOwnerDeletion: pointer.Bool(true),
58+
},
59+
})
60+
}
61+
62+
return bd
63+
}

0 commit comments

Comments
 (0)