From 849ef217f5c1d7716b0a5013576c17e492050ec8 Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Thu, 24 Oct 2024 20:28:08 +0200 Subject: [PATCH] add test Signed-off-by: Coleen Iona Quadros --- .../observatorium_test.go | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/operators/multiclusterobservability/controllers/multiclusterobservability/observatorium_test.go b/operators/multiclusterobservability/controllers/multiclusterobservability/observatorium_test.go index a38d06d71..19d250166 100644 --- a/operators/multiclusterobservability/controllers/multiclusterobservability/observatorium_test.go +++ b/operators/multiclusterobservability/controllers/multiclusterobservability/observatorium_test.go @@ -11,6 +11,8 @@ import ( "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" + routev1 "github.com/openshift/api/route/v1" mcoshared "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/shared" @@ -318,10 +320,24 @@ func TestUpdateObservatoriumCR(t *testing.T) { t.Errorf("config-hash label contains unexpected hash. Want: '%s', got '%s'", expectedConfigHash, updatedHash) } - createdSpecBytes, _ := yaml.Marshal(createdObservatoriumCR.Spec) - updatedSpecBytes, _ := yaml.Marshal(updatedObservatorium.Spec) - if res := bytes.Compare(updatedSpecBytes, createdSpecBytes); res != 0 { - t.Errorf("%v should be equal to %v", string(createdSpecBytes), string(updatedSpecBytes)) + if !equality.Semantic.DeepDerivative(updatedObservatorium.Spec, createdObservatoriumCR.Spec) { + t.Errorf("updated observatorium CR spec is not equal to the created one") + } + + // Test Observaotrium CR gets updated with new update from MCO + mco.Spec.StorageConfig.CompactStorageSize = "2Gi" + _, err = GenerateObservatoriumCR(cl, s, mco) + if err != nil { + t.Errorf("Failed to update observatorium due to %v", err) + } + updatedObservatorium = &observatoriumv1alpha1.Observatorium{} + cl.Get(context.TODO(), types.NamespacedName{ + Name: mcoconfig.GetDefaultCRName(), + Namespace: namespace, + }, updatedObservatorium) + + if updatedObservatorium.Spec.Thanos.Compact.VolumeClaimTemplate.Spec.Resources.Requests.Storage().String() != "2Gi" { + t.Errorf("Failed to update observatorium CR with new compact storage size") } }