From b7dd6122614d169dfaab80f08410eef8ac3da1d9 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Wed, 8 Nov 2023 11:14:36 +0000 Subject: [PATCH] Add UID to fake `Operator` objects in tests The code we test relies on UID and having UID set will ensure greater correctness of our tests. Signed-off-by: Mikalai Radchuk --- .../resolution/variablesources/bundle_deployment_test.go | 5 +++++ .../resolution/variablesources/installed_package_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/internal/resolution/variablesources/bundle_deployment_test.go b/internal/resolution/variablesources/bundle_deployment_test.go index 6a0dafa20..0069bc51c 100644 --- a/internal/resolution/variablesources/bundle_deployment_test.go +++ b/internal/resolution/variablesources/bundle_deployment_test.go @@ -16,6 +16,7 @@ import ( "github.com/operator-framework/operator-controller/internal/resolution/variablesources" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/utils/pointer" "github.com/operator-framework/deppy/pkg/deppy" @@ -26,6 +27,10 @@ func fakeOperator(name, packageName string, upgradeConstraintPolicy operatorsv1a return operatorsv1alpha1.Operator{ ObjectMeta: metav1.ObjectMeta{ Name: name, + // We manually set a fake UID here because the code we test + // uses UID to determine Operator CR which + // owns `BundleDeployment` + UID: uuid.NewUUID(), }, Spec: operatorsv1alpha1.OperatorSpec{ PackageName: packageName, diff --git a/internal/resolution/variablesources/installed_package_test.go b/internal/resolution/variablesources/installed_package_test.go index bd9271de7..6bfea03f4 100644 --- a/internal/resolution/variablesources/installed_package_test.go +++ b/internal/resolution/variablesources/installed_package_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/utils/pointer" @@ -207,6 +208,10 @@ func TestMakeInstalledPackageVariables(t *testing.T) { return operatorsv1alpha1.Operator{ ObjectMeta: metav1.ObjectMeta{ Name: name, + // We manually set a fake UID here because the code we test + // uses UID to determine Operator CR which + // owns `BundleDeployment` + UID: uuid.NewUUID(), }, Spec: operatorsv1alpha1.OperatorSpec{ PackageName: packageName,