@@ -79,27 +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 download - create the initial file
83- $firstResult = Save-SqlDscSqlServerMediaFile - Url $script :directIsoUrl - DestinationPath $overwriteTestPath - FileName ' overwrite-test.iso' - Force - Quiet - ErrorAction ' Stop'
82+ # Use SkipExecution to avoid the safety check while still testing Force parameter
83+ $executableUrl = ' https://download.microsoft.com/download/e/6/4/e6477a2a-9b58-40f7-8ad6-62bb8491ea78/SQLServerReportingServices.exe'
84+ $targetFileName = ' overwrite-test.exe'
8485
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
86+ # First, create a dummy file with the target name
87+ $dummyFilePath = Join-Path - Path $overwriteTestPath - ChildPath $targetFileName
88+ ' dummy content for overwrite test' | Out-File - FilePath $dummyFilePath - Encoding UTF8
9089
91- # Wait a moment to ensure different timestamps
92- Start-Sleep - Milliseconds 100
90+ # Verify the dummy file exists and get its original size
91+ Test-Path - Path $dummyFilePath | Should - BeTrue
92+ $originalSize = (Get-Item - Path $dummyFilePath ).Length
9393
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'
94+ # Download with SkipExecution and Force should overwrite the dummy file
95+ $result = Save-SqlDscSqlServerMediaFile - Url $executableUrl - DestinationPath $overwriteTestPath - FileName $targetFileName - SkipExecution - Force - Quiet - ErrorAction ' Stop'
9696
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
97+ # Verify the file was overwritten (should be much larger than the dummy content)
98+ $result | Should - BeOfType [System.IO.FileInfo ]
99+ $result .Name | Should - Be $targetFileName
100+ $result .Exists | Should - BeTrue
101+ $result .Length | Should - BeGreaterThan $originalSize
102+ $result .Length | Should - BeGreaterThan 1000000 # Executable should be at least 1MB
103103 }
104104 }
105105
0 commit comments