@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "os"
23+ "strings"
2324 "testing"
2425
2526 "github.com/Azure/go-autorest/autorest"
@@ -677,3 +678,86 @@ const (
677678 "cloudProviderBackoffJitter": 1.2000000000000002
678679}`
679680)
681+
682+ func Test_clusterIdentityFinalizer (t * testing.T ) {
683+ type args struct {
684+ prefix string
685+ clusterNamespace string
686+ clusterName string
687+ }
688+ tests := []struct {
689+ name string
690+ args args
691+ want string
692+ }{
693+ {
694+ name : "cluster identity finalizer should be deterministic" ,
695+ args : args {
696+ prefix : infrav1 .ClusterFinalizer ,
697+ clusterNamespace : "foo" ,
698+ clusterName : "bar" ,
699+ },
700+ want : "azurecluster.infrastructure.cluster.x-k8s.io/48998dbcd8fb929369c78981cbfb6f26145ea0412e6e05a1423941a6" ,
701+ },
702+ {
703+ name : "long cluster name and namespace" ,
704+ args : args {
705+ prefix : infrav1 .ClusterFinalizer ,
706+ clusterNamespace : "this-is-a-very-very-very-very-very-very-very-very-very-long-namespace-name" ,
707+ clusterName : "this-is-a-very-very-very-very-very-very-very-very-very-long-cluster-name" ,
708+ },
709+ want : "azurecluster.infrastructure.cluster.x-k8s.io/557d064144d2b495db694dedc53c9a1e9bd8575bdf06b5b151972614" ,
710+ },
711+ }
712+ for _ , tt := range tests {
713+ t .Run (tt .name , func (t * testing.T ) {
714+ got := clusterIdentityFinalizer (tt .args .prefix , tt .args .clusterNamespace , tt .args .clusterName )
715+ if got != tt .want {
716+ t .Errorf ("clusterIdentityFinalizer() = %v, want %v" , got , tt .want )
717+ }
718+ key := strings .Split (got , "/" )[1 ]
719+ if len (key ) > 63 {
720+ t .Errorf ("clusterIdentityFinalizer() name %v length = %v should be less than 63 characters" , key , len (key ))
721+ }
722+ })
723+ }
724+ }
725+
726+ func Test_deprecatedClusterIdentityFinalizer (t * testing.T ) {
727+ type args struct {
728+ prefix string
729+ clusterNamespace string
730+ clusterName string
731+ }
732+ tests := []struct {
733+ name string
734+ args args
735+ want string
736+ }{
737+ {
738+ name : "cluster identity finalizer should be deterministic" ,
739+ args : args {
740+ prefix : infrav1 .ClusterFinalizer ,
741+ clusterNamespace : "foo" ,
742+ clusterName : "bar" ,
743+ },
744+ want : "azurecluster.infrastructure.cluster.x-k8s.io/foo-bar" ,
745+ },
746+ {
747+ name : "long cluster name and namespace" ,
748+ args : args {
749+ prefix : infrav1 .ClusterFinalizer ,
750+ clusterNamespace : "this-is-a-very-very-very-very-very-very-very-very-very-long-namespace-name" ,
751+ clusterName : "this-is-a-very-very-very-very-very-very-very-very-very-long-cluster-name" ,
752+ },
753+ want : "azurecluster.infrastructure.cluster.x-k8s.io/this-is-a-very-very-very-very-very-very-very-very-very-long-namespace-name-this-is-a-very-very-very-very-very-very-very-very-very-long-cluster-name" ,
754+ },
755+ }
756+ for _ , tt := range tests {
757+ t .Run (tt .name , func (t * testing.T ) {
758+ if got := deprecatedClusterIdentityFinalizer (tt .args .prefix , tt .args .clusterNamespace , tt .args .clusterName ); got != tt .want {
759+ t .Errorf ("deprecatedClusterIdentityFinalizer() = %v, want %v" , got , tt .want )
760+ }
761+ })
762+ }
763+ }
0 commit comments