|
|
|
@@ -247,6 +247,43 @@ func TestScanBatch_Paginated(t *testing.T) { |
|
|
|
require.Len(t, items, scanPageSize+1) |
|
|
|
} |
|
|
|
|
|
|
|
func TestScanBatch_Rescan_PreservesHumanStrategy(t *testing.T) { |
|
|
|
db := setupMigrationServiceDB(t) |
|
|
|
orig := model.DB |
|
|
|
model.DB = db |
|
|
|
defer func() { |
|
|
|
model.DB = orig |
|
|
|
}() |
|
|
|
|
|
|
|
batch := &model.UserMigrationBatch{Name: "wave-rescan", SourceRegion: "ov", TargetRegion: "cn", OperatorId: 1} |
|
|
|
require.NoError(t, model.CreateUserMigrationBatch(batch)) |
|
|
|
|
|
|
|
client := &fakeClient{ |
|
|
|
listPages: map[int][]RemoteUserSnapshot{ |
|
|
|
0: {{ |
|
|
|
Id: 10000001, |
|
|
|
Username: "ov-dave", |
|
|
|
Email: "dave@example.com", |
|
|
|
Quota: 100, |
|
|
|
AffCode: "OVD1", |
|
|
|
}}, |
|
|
|
}, |
|
|
|
hasCopyResult: false, |
|
|
|
} |
|
|
|
svc := &Service{client: client} |
|
|
|
require.NoError(t, svc.ScanBatch(batch.Id)) |
|
|
|
|
|
|
|
require.NoError(t, db.Model(&model.UserMigrationItem{}).Where("batch_id = ?", batch.Id). |
|
|
|
Update("resolution_strategy", model.UserMigrationStrategySkip).Error) |
|
|
|
|
|
|
|
require.NoError(t, svc.ScanBatch(batch.Id)) |
|
|
|
|
|
|
|
items, err := model.ListUserMigrationItemsByBatch(batch.Id) |
|
|
|
require.NoError(t, err) |
|
|
|
require.Len(t, items, 1) |
|
|
|
require.Equal(t, model.UserMigrationStrategySkip, items[0].ResolutionStrategy) |
|
|
|
} |
|
|
|
|
|
|
|
func TestExecuteBatch_CreateNew_CreatesUserAndConvertsRemote(t *testing.T) { |
|
|
|
db := setupMigrationServiceDB(t) |
|
|
|
orig := model.DB |
|
|
|
@@ -435,6 +472,47 @@ func TestExecuteBatch_MergeExisting_IdempotentQuota(t *testing.T) { |
|
|
|
require.Len(t, client.convertCalls, 1) |
|
|
|
} |
|
|
|
|
|
|
|
func TestExecuteBatch_SkipItem_DoesNotConvert(t *testing.T) { |
|
|
|
db := setupMigrationServiceDB(t) |
|
|
|
orig := model.DB |
|
|
|
model.DB = db |
|
|
|
defer func() { |
|
|
|
model.DB = orig |
|
|
|
}() |
|
|
|
|
|
|
|
batch := &model.UserMigrationBatch{ |
|
|
|
Name: "skip-test", |
|
|
|
SourceRegion: "ov", |
|
|
|
TargetRegion: "cn", |
|
|
|
OperatorId: 1, |
|
|
|
Status: model.UserMigrationBatchStatusReady, |
|
|
|
} |
|
|
|
require.NoError(t, model.CreateUserMigrationBatch(batch)) |
|
|
|
require.NoError(t, model.UpsertUserMigrationItem(&model.UserMigrationItem{ |
|
|
|
BatchId: batch.Id, |
|
|
|
SourceUserId: 10000099, |
|
|
|
SourceUsername: "skip-user", |
|
|
|
SourceQuota: 50, |
|
|
|
ResolutionStrategy: model.UserMigrationStrategySkip, |
|
|
|
Status: model.UserMigrationItemStatusReady, |
|
|
|
MigrationToken: "batch-1-user-10000099", |
|
|
|
})) |
|
|
|
|
|
|
|
client := &fakeClient{} |
|
|
|
svc := &Service{client: client} |
|
|
|
|
|
|
|
locked, err := model.TryLockBatchForExecution(batch.Id) |
|
|
|
require.NoError(t, err) |
|
|
|
require.True(t, locked) |
|
|
|
require.NoError(t, svc.ExecuteBatch(batch.Id)) |
|
|
|
|
|
|
|
require.Len(t, client.convertCalls, 0) |
|
|
|
items, err := model.ListUserMigrationItemsByBatch(batch.Id) |
|
|
|
require.NoError(t, err) |
|
|
|
require.Len(t, items, 1) |
|
|
|
require.Equal(t, model.UserMigrationItemStatusSkipped, items[0].Status) |
|
|
|
} |
|
|
|
|
|
|
|
func TestVerifyItem_CorrectlyChecksRemoteConverted(t *testing.T) { |
|
|
|
db := setupMigrationServiceDB(t) |
|
|
|
orig := model.DB |
|
|
|
|