Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PSFramework/functions/temp/New-PSFTempFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}
process {
$newPath = Join-Path -Path $tempPath -ChildPath "PSF_Temp_$(New-Guid).$($Extension)"
if ($FileName) { Join-Path -Path $tempPath -ChildPath $FileName }
if ($FileName) { $newPath = Join-Path -Path $tempPath -ChildPath $FileName }
try { $null = New-Item -Path $newPath -ItemType File -Force -ErrorAction Stop }
catch { $PSCmdlet.ThrowTerminatingError($_) }

Expand Down
26 changes: 26 additions & 0 deletions PSFramework/tests/functions/temp/New-PSFTempFile.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Describe "New-PSFTempFile Unit Tests" -Tag "UnitTests" {
AfterEach {
Get-PSFTempItem -ModuleName PSFTests | Remove-PSFTempItem
}

It "Should create and track the file specified by -FileName" {
$fileName = "PSF_Test_$(New-Guid).csv"
$expected = Join-Path -Path (Get-PSFPath -Name Temp) -ChildPath $fileName

$result = New-PSFTempFile -ModuleName PSFTests -Name FileNameTest -FileName $fileName

@($result).Count | Should -Be 1
$result | Should -Be $expected
Test-Path -LiteralPath $expected | Should -BeTrue
(Get-PSFTempItem -ModuleName PSFTests -Name FileNameTest).Path | Should -Be $expected
}

It "Should create and track a generated file without -FileName" {
$result = New-PSFTempFile -ModuleName PSFTests -Name GeneratedTest -Extension csv

@($result).Count | Should -Be 1
$result | Should -BeLike '*\PSF_Temp_*.csv'
Test-Path -LiteralPath $result | Should -BeTrue
(Get-PSFTempItem -ModuleName PSFTests -Name GeneratedTest).Path | Should -Be $result
}
}