forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerShellData.tests.ps1
More file actions
66 lines (53 loc) · 2.06 KB
/
Copy pathPowerShellData.tests.ps1
File metadata and controls
66 lines (53 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" {
It "Validates error on a missing path" {
try
{
Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Validates error on a directory" {
try
{
Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Generates a good error on an insecure file" {
$path = Setup -f insecure.psd1 -content '@{ Foo = Get-Process }' -pass
try
{
Import-PowerShellDataFile $path -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Generates a good error on a file that isn't a PowerShell Data File (missing the hashtable root)" {
$path = setup -f NotAPSDataFile -content '"Hello World"' -Pass
try
{
Import-PowerShellDataFile $path -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" {
$path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass
$result = Import-PowerShellDataFile $path -ErrorAction Stop
$result.Hello | Should be "World"
}
}