Surface errors when writing to file

This commit is contained in:
Jeffrey
2026-08-12 17:31:50 +02:00
parent b21be418cd
commit dd929f8eec
2 changed files with 15 additions and 1 deletions
+13
View File
@@ -14,6 +14,19 @@ BeforeAll {
$script:JsonFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading'
}
Describe 'Save-ToFile' {
It 'reports the write error and returns false when persistence fails' {
Mock Set-Content { throw [System.IO.IOException]::new('Disk is full') }
Mock Write-Error {}
Save-ToFile -Config @{ Setting = $true } -FilePath (Join-Path $TestDrive 'settings.json') | Should -BeFalse
Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter {
$Message -eq "Failed to write '$TestDrive\settings.json': Disk is full"
}
}
}
Describe 'Import-Settings' {
BeforeEach {
$script:Params = @{}