@@ -48,4 +48,49 @@ Describe 'WindowsDiskCleanup.Tests' {
4848 Test-Path $path | Should - Be $true
4949 }
5050 }
51+
52+ Context ' Remove-CrashDump Tests' {
53+ BeforeAll {
54+ $LOCALAPPDATA = " $PSScriptRoot \LocalAppData"
55+ $env: LOCALAPPDATA = $LOCALAPPDATA
56+ $crashDumpPath = [System.IO.Path ]::Combine($env: LOCALAPPDATA , ' CrashDumps' )
57+ $testDumpFilePath = [System.IO.Path ]::Combine($crashDumpPath , ' test.dmp' )
58+
59+ if (-not (Test-Path $crashDumpPath )) {
60+ New-Item - Path $crashDumpPath - ItemType Directory - Force | Out-Null
61+ }
62+ }
63+
64+ BeforeEach {
65+ $file = New-Item - Path $testDumpFilePath - ItemType File - Force
66+ $file.CreationTimeUtc = (Get-Date ).AddDays(-10 )
67+ }
68+
69+ AfterEach {
70+ if (Test-Path $testDumpFilePath ) {
71+ Remove-Item - Path $testDumpFilePath - Force
72+ }
73+ }
74+
75+ AfterAll {
76+ if (Test-Path $LOCALAPPDATA ) {
77+ Remove-Item - Path $LOCALAPPDATA - Recurse - Force
78+ }
79+ }
80+
81+ It ' should remove crash dump files older than specified days' {
82+ Remove-CrashDump - Days 5 - DryRun:$false
83+ Test-Path $testDumpFilePath | Should - Be $false
84+ }
85+
86+ It ' should not remove crash dump files in dry run mode' {
87+ Remove-CrashDump - Days 5 - DryRun:$true
88+ Test-Path $testDumpFilePath | Should - Be $true
89+ }
90+
91+ It ' should do nothing if crash dump path does not exist' {
92+ Remove-Item - Path $crashDumpPath - Recurse - Force
93+ { Remove-CrashDump - Days 5 - DryRun:$false } | Should -Not - Throw
94+ }
95+ }
5196}
0 commit comments