Skip to content

Commit

Permalink
Unit tests for webhook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Oct 4, 2024
1 parent 4e2e498 commit afb9ee4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}

0 comments on commit afb9ee4

Please sign in to comment.