2018-02-13 09:23:53 -08:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" {
|
2016-07-25 11:06:55 -07:00
|
|
|
|
|
|
|
|
It "Validates error on a missing path" {
|
2018-03-23 10:26:23 -07:00
|
|
|
{ Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop } |
|
|
|
|
|
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Validates error on a directory" {
|
2018-03-23 10:26:23 -07:00
|
|
|
{ Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop } |
|
|
|
|
|
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
|
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
|
2018-03-23 10:26:23 -07:00
|
|
|
{ Import-PowerShellDataFile $path -ErrorAction Stop } |
|
|
|
|
|
Should -Throw -ErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
|
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
|
2018-03-23 10:26:23 -07:00
|
|
|
{ Import-PowerShellDataFile $path -ErrorAction Stop } |
|
|
|
|
|
Should -Throw -ErrorId "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
|
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
|
2016-07-25 11:06:55 -07:00
|
|
|
$result = Import-PowerShellDataFile $path -ErrorAction Stop
|
2018-03-23 10:26:23 -07:00
|
|
|
$result.Hello | Should -BeExactly "World"
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|
2017-01-16 13:31:14 -08:00
|
|
|
|
2016-07-25 11:06:55 -07:00
|
|
|
}
|