From afb9ee4b234af19a2286cb3b425df700e8d648f9 Mon Sep 17 00:00:00 2001 From: Miles Garnsey Date: Fri, 4 Oct 2024 14:29:46 +0400 Subject: [PATCH] Unit tests for webhook. --- .../v1alpha1/k8ssandracluster_webhook_test.go | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go b/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go index f39ad758f..e2d93af3f 100644 --- a/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go +++ b/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go @@ -20,12 +20,13 @@ import ( "context" "crypto/tls" "fmt" - "k8s.io/apimachinery/pkg/api/resource" "net" "path/filepath" "testing" "time" + "k8s.io/apimachinery/pkg/api/resource" + logrusr "github.com/bombsimon/logrusr/v2" "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1" "github.com/k8ssandra/k8ssandra-operator/pkg/clientcache" @@ -650,3 +651,25 @@ func testAutomatedUpdateAnnotation(t *testing.T) { cluster.Annotations[AutomatedUpdateAnnotation] = string("true") require.Error(cluster.validateK8ssandraCluster()) } + +func TestDcRemoved(t *testing.T) { + kcOld := createClusterObjWithCassandraConfig("testcluster", "testns") + kcNew := kcOld.DeepCopy() + kcOld.Spec.Cassandra.Datacenters = append(kcOld.Spec.Cassandra.Datacenters, CassandraDatacenterTemplate{ + Meta: EmbeddedObjectMeta{ + Name: "dc2", + }, + }) + require.True(t, DcRemoved(kcOld.Spec, kcNew.Spec)) +} + +func TestDcAdded(t *testing.T) { + kcOld := createClusterObjWithCassandraConfig("testcluster", "testns") + kcNew := kcOld.DeepCopy() + kcNew.Spec.Cassandra.Datacenters = append(kcOld.Spec.Cassandra.Datacenters, CassandraDatacenterTemplate{ + Meta: EmbeddedObjectMeta{ + Name: "dc2", + }, + }) + require.True(t, DcAdded(kcOld.Spec, kcNew.Spec)) +}