mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Change Import-PowerShellDataFile tag to CI and simplify tests
This commit is contained in:
1 parent
c610ea7941
commit
01c495b5e6
1 file changed
+12
-32
@@ -1,83 +1,63 @@
|
|||||||
Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "Feature" {
|
Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" {
|
||||||
|
|
||||||
It "Validates error on a missing path" {
|
It "Validates error on a missing path" {
|
||||||
|
|
||||||
$foundError = ""
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop
|
Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop
|
||||||
|
Throw "Execution OK"
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
$foundError = $_.FullyQualifiedErrorId
|
$_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand"
|
||||||
}
|
}
|
||||||
|
|
||||||
$foundError | Should be "PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validates error on a directory" {
|
It "Validates error on a directory" {
|
||||||
|
|
||||||
$foundError = ""
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop
|
Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop
|
||||||
|
Throw "Execution OK"
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
$foundError = $_.FullyQualifiedErrorId
|
$_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFile,Import-PowerShellDataFile"
|
||||||
}
|
}
|
||||||
|
|
||||||
$foundError | Should be "CouldNotParseAsPowerShellDataFile,Import-PowerShellDataFile"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Generates a good error on an insecure file" {
|
It "Generates a good error on an insecure file" {
|
||||||
|
|
||||||
$path = New-TemporaryFile
|
$path = Setup -f insecure.psd1 -content '@{ Foo = Get-Process }' -pass
|
||||||
Set-Content $path '@{ Foo = Get-Process }'
|
|
||||||
|
|
||||||
$foundError = ""
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Import-PowerShellDataFile $path -ErrorAction Stop
|
Import-PowerShellDataFile $path -ErrorAction Stop
|
||||||
|
Throw "Execution OK"
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
$foundError = $_.FullyQualifiedErrorId
|
$_.FullyQualifiedErrorId | Should be "InvalidOperationException,Import-PowerShellDataFile"
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
Remove-Item $path
|
|
||||||
}
|
|
||||||
|
|
||||||
$foundError | Should be "InvalidOperationException,Import-PowerShellDataFile"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Generates a good error on a file that isn't a PowerShell Data File (missing the hashtable root)" {
|
It "Generates a good error on a file that isn't a PowerShell Data File (missing the hashtable root)" {
|
||||||
|
|
||||||
$path = New-TemporaryFile
|
$path = setup -f NotAPSDataFile -content '"Hello World"' -Pass
|
||||||
Set-Content $path '"Hello World"'
|
|
||||||
|
|
||||||
$foundError = ""
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Import-PowerShellDataFile $path -ErrorAction Stop
|
Import-PowerShellDataFile $path -ErrorAction Stop
|
||||||
|
Throw "Execution OK"
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
$foundError = $_.FullyQualifiedErrorId
|
$_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Import-PowerShellDataFile"
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
Remove-Item $path
|
|
||||||
}
|
|
||||||
|
|
||||||
$foundError | Should be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Import-PowerShellDataFile"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" {
|
It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" {
|
||||||
|
|
||||||
$path = New-TemporaryFile
|
$path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass
|
||||||
Set-Content $path '@{ "Hello" = "World" }'
|
|
||||||
|
|
||||||
$result = Import-PowerShellDataFile $path -ErrorAction Stop
|
$result = Import-PowerShellDataFile $path -ErrorAction Stop
|
||||||
$result.Hello | Should be "World"
|
$result.Hello | Should be "World"
|
||||||
|
|||||||
Reference in new issue
Block a user