Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Commit 546f170

Browse files
committed
0.1.5
QA: - Added tests for remove-from-filesystem
1 parent 7930331 commit 546f170

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Describe 'Remove-File' {
2+
BeforeAll {
3+
. $PSScriptRoot/../src/remove-from-filesystem.ps1
4+
5+
Mock Write-Host {
6+
param($Object)
7+
$global:actualParameters = $Object
8+
}
9+
}
10+
11+
BeforeEach {
12+
$testPath = "TestDrive:\sample.txt"
13+
Set-Content $testPath -Value "lorem ipsum"
14+
}
15+
16+
It 'Should delete a file' {
17+
$realPath = "TestDrive:\sample.txt".Replace('TestDrive:', (Get-PSDrive TestDrive).Root)
18+
Test-Path -Path "TestDrive:\sample.txt" | Should -BeTrue
19+
20+
$result = Remove-File -fileName "TestDrive:\sample.txt" -size 11
21+
22+
Should -Invoke Write-Host -Exactly 1
23+
Should -Invoke Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Removed: $realPath - saved 11 bytes" }
24+
25+
Test-Path -Path "TestDrive:\sample.txt" | Should -BeFalse
26+
$result | Should -BeTrue
27+
}
28+
29+
It 'Should return false, because file does not exist' {
30+
Test-Path -Path "TestDrive:\non_exisiting_sample.txt" | Should -BeFalse
31+
32+
$result = Remove-File -fileName "TestDrive:\non_existing_sample.txt" -size 11
33+
Should -Not -Invoke Write-Host
34+
$result | Should -BeFalse
35+
}
36+
}
37+
38+
Describe 'Remove-Directory' {
39+
BeforeAll {
40+
. $PSScriptRoot/../src/remove-from-filesystem.ps1
41+
42+
Mock Write-Host {
43+
param($Object)
44+
$global:actualParameters = $Object
45+
}
46+
}
47+
48+
BeforeEach {
49+
New-Item -ItemType Directory -Force -Path TestDrive:\sample_directory
50+
$testPath = "TestDrive:\sample_directory\sample.txt"
51+
Set-Content $testPath -Value "lorem ipsum"
52+
}
53+
54+
It 'Should delete a directory' {
55+
Test-Path -Path "TestDrive:\sample_directory" | Should -BeTrue
56+
57+
$result = Remove-Directory -directoryName "TestDrive:\sample_directory" -size 11
58+
59+
Should -Invoke Write-Host -Exactly 1
60+
Should -Invoke Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Removed: TestDrive:\sample_directory - saved 11 bytes" }
61+
62+
Test-Path -Path "TestDrive:\sample_directory" | Should -BeFalse
63+
$result | Should -BeTrue
64+
}
65+
66+
It 'Should return false, because directory does not exist' {
67+
Test-Path -Path "TestDrive:\non_exisiting_directory" | Should -BeFalse
68+
69+
$result = Remove-Directory -directoryName "TestDrive:\non_existing_directory" -size 11
70+
Should -Not -Invoke Write-Host
71+
$result | Should -BeFalse
72+
}
73+
}

0 commit comments

Comments
 (0)