@@ -476,6 +476,137 @@ func TestDeprecateDomainRequest(t *testing.T) {
476476 FuzzOptions {},
477477 )
478478}
479+
480+ func TestFailoverDomainRequest (t * testing.T ) {
481+ // Test complete field mapping - all fields should now be properly mapped
482+ t .Run ("CompleteFieldMapping" , func (t * testing.T ) {
483+ // Create a thrift FailoverDomainRequest with all fields
484+ domainName := testdata .DomainName
485+ clusterName := testdata .ClusterName1
486+ thriftRequest := & shared.FailoverDomainRequest {
487+ DomainName : & domainName ,
488+ DomainActiveClusterName : & clusterName ,
489+ ActiveClusters : thrift .ActiveClusters (testdata .ActiveClusters ),
490+ }
491+
492+ // Convert to proto
493+ protoRequest := proto .FailoverDomainRequest (thriftRequest )
494+
495+ // Verify that all fields are mapped correctly
496+ assert .Equal (t , testdata .DomainName , protoRequest .DomainName )
497+ assert .Equal (t , testdata .ClusterName1 , protoRequest .DomainActiveClusterName )
498+ assert .NotNil (t , protoRequest .ActiveClusters , "ActiveClusters field should be mapped" )
499+
500+ // Test round-trip conversion
501+ convertedBack := thrift .FailoverDomainRequest (protoRequest )
502+ assert .NotNil (t , convertedBack )
503+ assert .Equal (t , testdata .DomainName , convertedBack .GetDomainName ())
504+ assert .Equal (t , testdata .ClusterName1 , convertedBack .GetDomainActiveClusterName ())
505+ assert .NotNil (t , convertedBack .ActiveClusters , "ActiveClusters should survive round-trip conversion" )
506+ })
507+
508+ // Test bidirectional conversion with standard test pattern
509+ t .Run ("BidirectionalConversion" , func (t * testing.T ) {
510+ for _ , item := range []* apiv1.FailoverDomainRequest {nil , {}, & testdata .FailoverDomainRequest } {
511+ assert .Equal (t , item , proto .FailoverDomainRequest (thrift .FailoverDomainRequest (item )))
512+ }
513+ })
514+
515+ // Test with nil and empty cases
516+ t .Run ("NilAndEmptyCases" , func (t * testing.T ) {
517+ assert .Nil (t , proto .FailoverDomainRequest (nil ))
518+ assert .Nil (t , thrift .FailoverDomainRequest (nil ))
519+
520+ emptyRequest := & shared.FailoverDomainRequest {}
521+ converted := proto .FailoverDomainRequest (emptyRequest )
522+ assert .NotNil (t , converted )
523+ assert .Equal (t , "" , converted .DomainName )
524+ assert .Equal (t , "" , converted .DomainActiveClusterName )
525+ assert .Nil (t , converted .ActiveClusters )
526+ })
527+
528+ // Fuzz test to ensure robustness
529+ runFuzzTest (t ,
530+ thrift .FailoverDomainRequest ,
531+ proto .FailoverDomainRequest ,
532+ FuzzOptions {
533+ ExcludedFields : []string {
534+ "RegionToCluster" , // [DEPRECATED] This field is deprecated and not mapped in conversion functions
535+ },
536+ },
537+ )
538+ }
539+
540+ func TestFailoverDomainResponse (t * testing.T ) {
541+ // Test complete bidirectional conversion
542+ t .Run ("BidirectionalConversion" , func (t * testing.T ) {
543+ // Test nil case
544+ assert .Nil (t , proto .FailoverDomainResponse (thrift .FailoverDomainResponse (nil )))
545+
546+ // Test empty case - empty response should create a response with nil domain
547+ emptyResponse := & apiv1.FailoverDomainResponse {}
548+ converted := proto .FailoverDomainResponse (thrift .FailoverDomainResponse (emptyResponse ))
549+ assert .Nil (t , converted ) // thrift.FailoverDomainResponse returns nil for empty response
550+
551+ // Test full response
552+ fullResponse := & testdata .FailoverDomainResponse
553+ assert .Equal (t , fullResponse , proto .FailoverDomainResponse (thrift .FailoverDomainResponse (fullResponse )))
554+ })
555+
556+ // Test that both conversion directions work
557+ t .Run ("ConversionDirections" , func (t * testing.T ) {
558+ // Test proto -> thrift
559+ thriftResponse := thrift .FailoverDomainResponse (& testdata .FailoverDomainResponse )
560+ assert .NotNil (t , thriftResponse )
561+ assert .NotNil (t , thriftResponse .DomainInfo )
562+ assert .Equal (t , testdata .DomainName , * thriftResponse .DomainInfo .Name )
563+
564+ // Test thrift -> proto
565+ protoResponse := proto .FailoverDomainResponse (thriftResponse )
566+ assert .NotNil (t , protoResponse )
567+ assert .NotNil (t , protoResponse .Domain )
568+ assert .Equal (t , testdata .DomainName , protoResponse .Domain .Name )
569+ })
570+
571+ // Fuzz test for robustness
572+ runFuzzTest (t ,
573+ thrift .FailoverDomainResponse ,
574+ proto .FailoverDomainResponse ,
575+ FuzzOptions {
576+ CustomFuncs : []interface {}{
577+ func (status * apiv1.DomainStatus , c fuzz.Continue ) {
578+ validValues := []apiv1.DomainStatus {
579+ apiv1 .DomainStatus_DOMAIN_STATUS_INVALID ,
580+ apiv1 .DomainStatus_DOMAIN_STATUS_REGISTERED ,
581+ apiv1 .DomainStatus_DOMAIN_STATUS_DEPRECATED ,
582+ apiv1 .DomainStatus_DOMAIN_STATUS_DELETED ,
583+ }
584+ * status = validValues [c .Intn (len (validValues ))]
585+ },
586+ func (status * apiv1.ArchivalStatus , c fuzz.Continue ) {
587+ validValues := []apiv1.ArchivalStatus {
588+ apiv1 .ArchivalStatus_ARCHIVAL_STATUS_INVALID ,
589+ apiv1 .ArchivalStatus_ARCHIVAL_STATUS_DISABLED ,
590+ apiv1 .ArchivalStatus_ARCHIVAL_STATUS_ENABLED ,
591+ }
592+ * status = validValues [c .Intn (len (validValues ))]
593+ },
594+ // WorkflowExecutionRetentionPeriod - must be day-precision
595+ func (domain * apiv1.Domain , c fuzz.Continue ) {
596+ if domain .WorkflowExecutionRetentionPeriod != nil {
597+ days := c .Int63n (MaxDurationSeconds / (24 * 3600 ))
598+ domain .WorkflowExecutionRetentionPeriod .Seconds = days * 24 * 3600
599+ domain .WorkflowExecutionRetentionPeriod .Nanos = 0
600+ }
601+ },
602+ },
603+ ExcludedFields : []string {
604+ "RegionToCluster" , // [DEPRECATED] This field is deprecated and not mapped in conversion functions
605+ },
606+ },
607+ )
608+ }
609+
479610func TestDescribeDomainRequest (t * testing.T ) {
480611 for _ , item := range []* apiv1.DescribeDomainRequest {
481612 & testdata .DescribeDomainRequest_ID ,
@@ -3047,7 +3178,7 @@ func clearFieldsIf(obj interface{}, shouldClear func(fieldName string) bool) {
30473178 field .Set (reflect .Zero (field .Type ()))
30483179 }
30493180
3050- // Recursively clear fields in nested structs and slices
3181+ // Recursively clear fields in nested structs, slices, and maps
30513182 if field .CanInterface () {
30523183 switch field .Kind () {
30533184 case reflect .Ptr :
@@ -3063,6 +3194,13 @@ func clearFieldsIf(obj interface{}, shouldClear func(fieldName string) bool) {
30633194 clearFieldsIf (elem .Interface (), shouldClear )
30643195 }
30653196 }
3197+ case reflect .Map :
3198+ for _ , key := range field .MapKeys () {
3199+ elem := field .MapIndex (key )
3200+ if elem .CanInterface () {
3201+ clearFieldsIf (elem .Interface (), shouldClear )
3202+ }
3203+ }
30663204 }
30673205 }
30683206 }
0 commit comments