2016-08-24 11:53:48 -07:00
|
|
|
Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" {
|
2016-07-25 11:06:55 -07:00
|
|
|
|
|
|
|
|
It "Validates error on a missing path" {
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop
|
2016-08-30 16:52:00 -07:00
|
|
|
Throw "Command did not throw exception"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2016-08-24 11:53:48 -07:00
|
|
|
$_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Validates error on a directory" {
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop
|
2016-08-30 16:52:00 -07:00
|
|
|
Throw "Command did not throw exception"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2016-08-24 11:53:48 -07:00
|
|
|
$_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFile,Import-PowerShellDataFile"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
2017-01-16 13:31:14 -08:00
|
|
|
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Generates a good error on an insecure file" {
|
|
|
|
|
|
2016-08-24 11:53:48 -07:00
|
|
|
$path = Setup -f insecure.psd1 -content '@{ Foo = Get-Process }' -pass
|
2016-07-25 11:06:55 -07:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Import-PowerShellDataFile $path -ErrorAction Stop
|
2016-08-30 16:52:00 -07:00
|
|
|
Throw "Command did not throw exception"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2016-08-24 11:53:48 -07:00
|
|
|
$_.FullyQualifiedErrorId | Should be "InvalidOperationException,Import-PowerShellDataFile"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Generates a good error on a file that isn't a PowerShell Data File (missing the hashtable root)" {
|
|
|
|
|
|
2016-08-24 11:53:48 -07:00
|
|
|
$path = setup -f NotAPSDataFile -content '"Hello World"' -Pass
|
2016-07-25 11:06:55 -07:00
|
|
|
try
|
|
|
|
|
{
|
2017-01-16 13:31:14 -08:00
|
|
|
Import-PowerShellDataFile $path -ErrorAction Stop
|
2016-08-30 16:52:00 -07:00
|
|
|
Throw "Command did not throw exception"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2016-08-24 11:53:48 -07:00
|
|
|
$_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Import-PowerShellDataFile"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" {
|
|
|
|
|
|
2016-08-24 11:53:48 -07:00
|
|
|
$path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass
|
2017-01-16 13:31:14 -08:00
|
|
|
|
2016-07-25 11:06:55 -07:00
|
|
|
$result = Import-PowerShellDataFile $path -ErrorAction Stop
|
|
|
|
|
$result.Hello | Should be "World"
|
|
|
|
|
}
|
2017-01-16 13:31:14 -08:00
|
|
|
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|