@@ -464,27 +464,73 @@ func TestLegacyNamespaceDetection(t *testing.T) {
464464 manager .namespaceMigrationCompleted .Store (false )
465465
466466 // Check if we should expect a legacy namespace check
467- // This happens when legacy namespace is different from header/data namespaces
468- expectLegacyCheck := tt .legacyNamespace != "" &&
469- tt .legacyNamespace != headerNS &&
470- tt .legacyNamespace != dataNS
471-
472- if expectLegacyCheck {
473- // Should try legacy namespace first
474- mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (tt .legacyNamespace )).Return (& coreda.GetIDsResult {
475- IDs : []coreda.ID {},
476- }, coreda .ErrBlobNotFound ).Once ()
477- }
478-
479- // Then should try new namespaces
480- mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (headerNS )).Return (& coreda.GetIDsResult {
481- IDs : []coreda.ID {},
482- }, coreda .ErrBlobNotFound ).Once ()
483-
484- if dataNS != headerNS {
485- mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (dataNS )).Return (& coreda.GetIDsResult {
486- IDs : []coreda.ID {},
487- }, coreda .ErrBlobNotFound ).Once ()
467+ // Legacy check happens when migration is not completed and legacy namespace is configured
468+ if tt .legacyNamespace != "" {
469+ // When legacy namespace is the same as header/data namespaces,
470+ // the legacy check still happens first (it's a separate call)
471+ if tt .legacyNamespace == headerNS && headerNS == dataNS {
472+ // All three namespaces are the same, so we'll get 3 calls total:
473+ // 1 for legacy check + 1 for header + 1 for data
474+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (tt .legacyNamespace )).Return (& coreda.GetIDsResult {
475+ IDs : []coreda.ID {},
476+ }, coreda .ErrBlobNotFound ).Times (3 )
477+ } else if tt .legacyNamespace == headerNS || tt .legacyNamespace == dataNS {
478+ // Legacy matches one of the new namespaces
479+ // We'll get the legacy call plus one or two more depending on whether header == data
480+ totalCalls := 1 // legacy call
481+ if headerNS == dataNS {
482+ totalCalls += 2 // header and data are same
483+ } else {
484+ totalCalls += 1 // the one that matches legacy
485+ }
486+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (tt .legacyNamespace )).Return (& coreda.GetIDsResult {
487+ IDs : []coreda.ID {},
488+ }, coreda .ErrBlobNotFound ).Times (totalCalls )
489+
490+ // Mock the non-matching namespace if header != data
491+ if headerNS != dataNS {
492+ nonMatchingNS := headerNS
493+ if tt .legacyNamespace == headerNS {
494+ nonMatchingNS = dataNS
495+ }
496+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (nonMatchingNS )).Return (& coreda.GetIDsResult {
497+ IDs : []coreda.ID {},
498+ }, coreda .ErrBlobNotFound ).Once ()
499+ }
500+ } else {
501+ // Legacy is different from both header and data
502+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (tt .legacyNamespace )).Return (& coreda.GetIDsResult {
503+ IDs : []coreda.ID {},
504+ }, coreda .ErrBlobNotFound ).Once ()
505+
506+ // Mock header and data calls
507+ if headerNS == dataNS {
508+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (headerNS )).Return (& coreda.GetIDsResult {
509+ IDs : []coreda.ID {},
510+ }, coreda .ErrBlobNotFound ).Twice ()
511+ } else {
512+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (headerNS )).Return (& coreda.GetIDsResult {
513+ IDs : []coreda.ID {},
514+ }, coreda .ErrBlobNotFound ).Once ()
515+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (dataNS )).Return (& coreda.GetIDsResult {
516+ IDs : []coreda.ID {},
517+ }, coreda .ErrBlobNotFound ).Once ()
518+ }
519+ }
520+ } else {
521+ // No legacy namespace configured, just mock the new namespace calls
522+ if headerNS == dataNS {
523+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (headerNS )).Return (& coreda.GetIDsResult {
524+ IDs : []coreda.ID {},
525+ }, coreda .ErrBlobNotFound ).Twice ()
526+ } else {
527+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (headerNS )).Return (& coreda.GetIDsResult {
528+ IDs : []coreda.ID {},
529+ }, coreda .ErrBlobNotFound ).Once ()
530+ mockDA .On ("GetIDs" , mock .Anything , uint64 (100 ), []byte (dataNS )).Return (& coreda.GetIDsResult {
531+ IDs : []coreda.ID {},
532+ }, coreda .ErrBlobNotFound ).Once ()
533+ }
488534 }
489535
490536 ctx := context .Background ()
0 commit comments