-
Notifications
You must be signed in to change notification settings - Fork 48
/
AutomateAPI.tests.ps1
58 lines (51 loc) · 2.17 KB
/
AutomateAPI.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
#using Pester to run tests
#Remove module from memory
Get-Module AutomateAPI | Remove-Module -Force
Import-Module "$PSScriptRoot\\AutomateAPI.psm1" -Force
#Get credentials $creds is available in every test
#Copy credentials.example.json to a new file credentials.json
$creds = $null
if(Test-Path "$PSScriptRoot\\credentials.json") {
$creds = Get-Content "$PSScriptRoot\\credentials.json" | Out-String | ConvertFrom-Json
}
Describe AutomateAPI {
It "AutomateAPI is valid PowerShell code" {
$psFile = Get-Content -Path "$PSScriptRoot\\AutomateAPI.psm1" -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($psFile, [ref]$errors)
$errors.Count | Should -Be 0
}
It "Connects to the Automate API" {
if($creds) {
$password = ConvertTo-SecureString $creds.Automate.password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($creds.Automate.user, $password)
$result = Connect-AutomateAPI -Server $creds.Automate.server -Credential $credentials `
-ClientID $creds.Automate.clientid
}
else {
$result = Connect-AutomateAPI
}
$result | Should -be $null
}
It "Automate API returns a list of computers" {
(Get-AutomateComputer).Count | Should -BeGreaterThan 0
}
It "Connects to the Control API" {
if($creds) {
$password = ConvertTo-SecureString $creds.Control.password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($creds.Control.user, $password)
$result = Connect-ControlAPI -Server $creds.Control.server -Credential $credentials
}
else {
$result = Connect-ControlAPI
}
$result | Should -be $null
}
It "Control API returns a list of sessions" {
(Get-ControlSession).Count | Should -BeGreaterThan 0
}
It "Compares Automate Control Status" {
$result = Get-AutomateComputer -Online $true | Select-Object -First 1 | Compare-AutomateControlStatus -AllResults
$result | Should -Not -Be $null
}
}