@@ -79,19 +79,27 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag @('Integration_SQL2017', 'Integrat
7979 $overwriteTestPath = Join-Path - Path $script :testDownloadPath - ChildPath ' OverwriteTest'
8080 New-Item - Path $overwriteTestPath - ItemType Directory - Force | Out-Null
8181
82- # First, create a dummy file
83- $dummyFilePath = Join-Path - Path $overwriteTestPath - ChildPath ' overwrite-test.iso'
84- ' dummy content' | Out-File - FilePath $dummyFilePath - Encoding UTF8
82+ # First download - create the initial file
83+ $firstResult = Save-SqlDscSqlServerMediaFile - Url $script :directIsoUrl - DestinationPath $overwriteTestPath - FileName ' overwrite-test.iso' - Force - Quiet - ErrorAction ' Stop'
8584
86- # Verify the dummy file exists
87- Test-Path - Path $dummyFilePath | Should - BeTrue
85+ # Verify the first download worked
86+ $firstResult | Should - BeOfType [System.IO.FileInfo ]
87+ $firstResult.Name | Should - Be ' overwrite-test.iso'
88+ $firstResult.Exists | Should - BeTrue
89+ $originalSize = $firstResult.Length
8890
89- # Download should overwrite the dummy file
90- $result = Save-SqlDscSqlServerMediaFile - Url $ script :directIsoUrl - DestinationPath $overwriteTestPath - FileName ' overwrite-test.iso ' - Force - Quiet - ErrorAction ' Stop '
91+ # Wait a moment to ensure different timestamps
92+ Start-Sleep - Milliseconds 100
9193
92- # Verify the file was overwritten (should be much larger than the dummy content)
93- $result.Length | Should - BeGreaterThan 100
94- $result.Name | Should - Be ' overwrite-test.iso'
94+ # Second download with Force should overwrite the existing file
95+ $secondResult = Save-SqlDscSqlServerMediaFile - Url $script :directIsoUrl - DestinationPath $overwriteTestPath - FileName ' overwrite-test.iso' - Force - Quiet - ErrorAction ' Stop'
96+
97+ # Verify the file was overwritten successfully
98+ $secondResult | Should - BeOfType [System.IO.FileInfo ]
99+ $secondResult.Name | Should - Be ' overwrite-test.iso'
100+ $secondResult.Exists | Should - BeTrue
101+ # File size should be the same (same download) but this confirms it worked
102+ $secondResult.Length | Should - Be $originalSize
95103 }
96104 }
97105
0 commit comments