forked from PowerShell/Remotely
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Remotely.Tests.ps1
117 lines (97 loc) · 3.62 KB
/
Remotely.Tests.ps1
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Describe "Add-Numbers" {
It "can execute script" {
Remotely { 1 + 1 } | Should Be 2
}
It "can return an array" {
$returnObjs = Remotely { 1..10 }
$returnObjs.count | Should Be 10
}
It "can return a hashtable" {
$returnObjs = Remotely { @{Value = 2} }
$returnObjs["Value"] | Should Be 2
}
It "can get verbose message" {
$output = Remotely { Write-Verbose -Verbose "Verbose Message" }
$output.GetVerbose() | Should Be "Verbose Message"
}
It "can get error message" {
$output = Remotely { Write-Error "Error Message" }
$output.GetError() | Should Be "Error Message"
}
It "can get warning message" {
$output = Remotely { Write-Warning "Warning Message" }
$output.GetWarning() | Should Be "Warning Message"
}
It "can get debug message" {
$output = Remotely {
$originalPreference = $DebugPreference
$DebugPreference = "continue"
Write-Debug "Debug Message"
$DebugPreference = $originalPreference
}
$output.GetDebugOutput() | Should Be "Debug Message"
}
It "can get progress message" {
$output = Remotely { Write-Progress -Activity "Test" -Status "Testing" -Id 1 -PercentComplete 100 -SecondsRemaining 0 }
$output.GetProgressOutput().Activity | Should Be "Test"
$output.GetProgressOutput().StatusDescription | Should Be "Testing"
$output.GetProgressOutput().ActivityId | Should Be 1
}
It 'can return $false as a value' {
$output = Remotely { $false }
$output | Should Be $false
}
It 'can return throw messages' {
$output = Remotely { throw 'bad' }
$output.GetError().FullyQualifiedErrorId | Should Be 'bad'
}
It "can get remote sessions" {
Remotely { 1 + 1 } | Should Be 2
$remoteSessions = Get-RemoteSession
$remoteSessions | % { $remoteSessions.Name -match "Remotely" | Should Be $true}
}
It "can pass parameters to remote block" {
$num = 10
$process = Remotely { param($number) $number + 1 } -ArgumentList $num
$process | Should Be 11
}
It "can get target of the remotely block" {
$output = Remotely { 1 }
$output.RemotelyTarget | Should Be "localhost"
}
It "can handle delete sessions" {
Remotely { 1 + 1 } | Should Be 2
$previousSession = Get-RemoteSession
$previousSession | Remove-PSSession
##New session should be created
Remotely { 1 + 1 } | Should Be 2
$newSession = Get-RemoteSession
$previousSession.Name | Should Not Be $newSession.Name
}
It "can execute against more than 1 remote machines" {
$configFile = (join-path $PSScriptRoot 'machineConfig.csv')
$configContent = @([pscustomobject] @{ComputerName = "localhost" }, [pscustomobject] @{ComputerName = "." }) | ConvertTo-Csv -NoTypeInformation
$configContent | Out-File -FilePath $configFile -Force
try
{
$results = Remotely { 1 + 1 }
$results.Count | Should Be 2
foreach($result in $results)
{
$result | Should Be 2
}
}
catch
{
$_.FullyQualifiedErrorId | Should Be $null
}
finally
{
Remove-Item $configFile -ErrorAction SilentlyContinue -Force
}
}
It "can clear remote sessions" {
Clear-RemoteSession
Get-PSSession -Name Remotely* | Should Be $null
}
}