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