Skip to content

Commit b5c6bc9

Browse files
authored
Add UID to fake Operator objects in tests (#523)
The code we test relies on UID and having UID set will ensure greater correctness of our tests. Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
1 parent e9fd250 commit b5c6bc9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/resolution/variablesources/bundle_deployment_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
1717

1818
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
"k8s.io/apimachinery/pkg/util/uuid"
1920
"k8s.io/utils/pointer"
2021

2122
"github.com/operator-framework/deppy/pkg/deppy"
@@ -26,6 +27,10 @@ func fakeOperator(name, packageName string, upgradeConstraintPolicy operatorsv1a
2627
return operatorsv1alpha1.Operator{
2728
ObjectMeta: metav1.ObjectMeta{
2829
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(),
2934
},
3035
Spec: operatorsv1alpha1.OperatorSpec{
3136
PackageName: packageName,

internal/resolution/variablesources/installed_package_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
"k8s.io/apimachinery/pkg/util/uuid"
1415
featuregatetesting "k8s.io/component-base/featuregate/testing"
1516
"k8s.io/utils/pointer"
1617

@@ -207,6 +208,10 @@ func TestMakeInstalledPackageVariables(t *testing.T) {
207208
return operatorsv1alpha1.Operator{
208209
ObjectMeta: metav1.ObjectMeta{
209210
Name: name,
211+
// We manually set a fake UID here because the code we test
212+
// uses UID to determine Operator CR which
213+
// owns `BundleDeployment`
214+
UID: uuid.NewUUID(),
210215
},
211216
Spec: operatorsv1alpha1.OperatorSpec{
212217
PackageName: packageName,

0 commit comments

Comments
 (0)