2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
# This is a Pester test suite to validate the New-TemporaryFile cmdlet in the Microsoft.PowerShell.Utility module.
|
2016-07-25 11:06:55 -07:00
|
|
|
|
|
|
|
|
<#
|
|
|
|
|
Purpose:
|
|
|
|
|
Verify that New-TemporaryFile creates a temporary file.
|
2017-01-16 13:31:14 -08:00
|
|
|
|
2016-07-25 11:06:55 -07:00
|
|
|
Action:
|
|
|
|
|
Run New-TemporaryFile.
|
2017-01-16 13:31:14 -08:00
|
|
|
|
|
|
|
|
Expected Result:
|
|
|
|
|
A FileInfo object for the temporary file is returned.
|
2016-07-25 11:06:55 -07:00
|
|
|
#>
|
|
|
|
|
|
2018-02-22 19:32:01 +00:00
|
|
|
Describe "New-TemporaryFile" -Tags "CI" {
|
2016-07-25 11:06:55 -07:00
|
|
|
|
|
|
|
|
It "creates a new temporary file" {
|
2017-01-16 13:31:14 -08:00
|
|
|
$tempFile = New-TemporaryFile
|
2016-07-25 11:06:55 -07:00
|
|
|
|
2018-03-23 10:26:23 -07:00
|
|
|
$tempFile | Should -Exist
|
|
|
|
|
$tempFile | Should -BeOfType System.IO.FileInfo
|
|
|
|
|
$tempFile | Should -BeLikeExactly "$([System.IO.Path]::GetTempPath())*"
|
2016-07-25 11:06:55 -07:00
|
|
|
|
2018-02-22 19:32:01 +00:00
|
|
|
if (Test-Path $tempFile) {
|
2016-07-25 11:06:55 -07:00
|
|
|
Remove-Item $tempFile -ErrorAction SilentlyContinue -Force
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "with WhatIf does not create a file" {
|
2018-03-23 10:26:23 -07:00
|
|
|
New-TemporaryFile -WhatIf | Should -BeNullOrEmpty
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "has an OutputType of System.IO.FileInfo" {
|
2018-03-23 10:26:23 -07:00
|
|
|
(Get-Command New-TemporaryFile).OutputType | Should -BeExactly "System.IO.FileInfo"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
}
|