Skip to content

Commit 6a595c8

Browse files
committed
Refactor Restore-SqlDscDatabase integration tests to store file information instead of RelocateFile objects for better clarity and maintainability
1 parent 57fcc4c commit 6a595c8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tests/Integration/Commands/Restore-SqlDscDatabase.Integration.Tests.ps1

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,11 @@ WITH NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10;
825825
$script:perfTuneDbName = 'SqlDscRestorePerfTune_' + (Get-Random)
826826
$script:createdDatabases += $script:perfTuneDbName
827827

828-
# Get the file list from the backup to build RelocateFile objects
828+
# Get the file list from the backup to store file information
829829
$fileList = Get-SqlDscBackupFileList -ServerObject $script:serverObject -BackupFile $script:fullBackupFile -ErrorAction 'Stop'
830830

831-
$script:perfTuneRelocateFiles = @()
831+
# Store the original file information (not RelocateFile objects which get modified by SMO)
832+
$script:perfTuneFileInfo = @()
832833

833834
foreach ($file in $fileList)
834835
{
@@ -845,8 +846,10 @@ WITH NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10;
845846
$newPath = Join-Path -Path $script:dataDirectory -ChildPath $newFileName
846847
}
847848

848-
$relocateFile = [Microsoft.SqlServer.Management.Smo.RelocateFile]::new($file.LogicalName, $newPath)
849-
$script:perfTuneRelocateFiles += $relocateFile
849+
$script:perfTuneFileInfo += @{
850+
LogicalName = $file.LogicalName
851+
PhysicalName = $newPath
852+
}
850853
}
851854
}
852855

@@ -863,9 +866,9 @@ WITH NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10;
863866
$blockSizeDbName = $script:perfTuneDbName + '_BlockSize'
864867
$script:createdDatabases += $blockSizeDbName
865868

866-
# Create unique RelocateFile objects for this test
869+
# Create new RelocateFile objects for this test from the stored file information
867870
$blockSizeRelocateFiles = @()
868-
foreach ($file in $script:perfTuneRelocateFiles)
871+
foreach ($file in $script:perfTuneFileInfo)
869872
{
870873
$newPath = $file.PhysicalName -replace [regex]::Escape($script:perfTuneDbName), $blockSizeDbName
871874
$relocateFile = [Microsoft.SqlServer.Management.Smo.RelocateFile]::new($file.LogicalName, $newPath)
@@ -884,9 +887,9 @@ WITH NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10;
884887
$bufferCountDbName = $script:perfTuneDbName + '_BufferCount'
885888
$script:createdDatabases += $bufferCountDbName
886889

887-
# Create unique RelocateFile objects for this test
890+
# Create new RelocateFile objects for this test from the stored file information
888891
$bufferCountRelocateFiles = @()
889-
foreach ($file in $script:perfTuneRelocateFiles)
892+
foreach ($file in $script:perfTuneFileInfo)
890893
{
891894
$newPath = $file.PhysicalName -replace [regex]::Escape($script:perfTuneDbName), $bufferCountDbName
892895
$relocateFile = [Microsoft.SqlServer.Management.Smo.RelocateFile]::new($file.LogicalName, $newPath)
@@ -905,9 +908,9 @@ WITH NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10;
905908
$maxTransferDbName = $script:perfTuneDbName + '_MaxTransfer'
906909
$script:createdDatabases += $maxTransferDbName
907910

908-
# Create unique RelocateFile objects for this test
911+
# Create new RelocateFile objects for this test from the stored file information
909912
$maxTransferRelocateFiles = @()
910-
foreach ($file in $script:perfTuneRelocateFiles)
913+
foreach ($file in $script:perfTuneFileInfo)
911914
{
912915
$newPath = $file.PhysicalName -replace [regex]::Escape($script:perfTuneDbName), $maxTransferDbName
913916
$relocateFile = [Microsoft.SqlServer.Management.Smo.RelocateFile]::new($file.LogicalName, $newPath)
@@ -926,9 +929,9 @@ WITH NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10;
926929
$combinedDbName = $script:perfTuneDbName + '_Combined'
927930
$script:createdDatabases += $combinedDbName
928931

929-
# Create unique RelocateFile objects for this test
932+
# Create new RelocateFile objects for this test from the stored file information
930933
$combinedRelocateFiles = @()
931-
foreach ($file in $script:perfTuneRelocateFiles)
934+
foreach ($file in $script:perfTuneFileInfo)
932935
{
933936
$newPath = $file.PhysicalName -replace [regex]::Escape($script:perfTuneDbName), $combinedDbName
934937
$relocateFile = [Microsoft.SqlServer.Management.Smo.RelocateFile]::new($file.LogicalName, $newPath)

0 commit comments

Comments
 (0)