Skip to content

Commit

Permalink
Merge pull request #17 from alagoutte/tests
Browse files Browse the repository at this point in the history
Add Connection Tests (via Pester)
  • Loading branch information
alagoutte authored Aug 26, 2019
2 parents 85a7560 + 716dd6f commit e3cd72e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PowerArubaCP/Private/RestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function Invoke-ArubaCPRestMethod {

Process {

if ($null -eq $DefaultArubaCPConnection){
Throw "Not Connected. Connect to the ClearPass with Connect-ArubaCP"
}

$Server = ${DefaultArubaCPConnection}.Server
$invokeParams = ${DefaultArubaCPConnection}.invokeParams
$fullurl = "https://${Server}/${uri}"
Expand Down
1 change: 1 addition & 0 deletions Tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
credential.ps1
18 changes: 18 additions & 0 deletions Tests/common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright 2019, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

if ("Desktop" -eq $PSVersionTable.PsEdition) { # -BeOfType is not same on PowerShell Core and Desktop (get int with Desktop and long with Core for number)
$script:pester_longint = "int"
}
else {
$script:pester_longint = "long"
}

. ../credential.ps1
#TODO: Add check if no ipaddress/token info...

Connect-ArubaCP -Server $ipaddress -Token $token -SkipCertificateCheck

10 changes: 10 additions & 0 deletions Tests/credential.example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright 2019, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

# Copy this file to credential.ps1 (on Tests folder) and change connection settings..

$ipaddress = "10.44.23.213"
$token = "aaaaaaaaaaaaaaaaaa"
35 changes: 35 additions & 0 deletions Tests/integration/Connection.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright 2019, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#
. ../common.ps1

Describe "Connect to a ClearPass (using Token)" {
BeforeAll {
#Disconnect "default connection"
Disconnect-ArubaCP -noconfirm
}
It "Connect to ClearPass (using Token) and check global variable" {
Connect-ArubaCP $ipaddress -Token $token -SkipCertificateCheck
$DefaultArubaCPConnection | Should Not BeNullOrEmpty
$DefaultArubaCPConnection.server | Should be $ipaddress
$DefaultArubaCPConnection.token | Should be $token
}
It "Disconnect to ClearPass and check global variable" {
Disconnect-ArubaCP -noconfirm
$DefaultArubaCPConnection | Should be $null
}
#TODO: Connect using wrong login/password

#This test only work with PowerShell 6 / Core (-SkipCertificateCheck don't change global variable but only Invoke-WebRequest/RestMethod)
#This test will be fail, if there is valid certificate...
It "Throw when try to use Invoke-ArubaCPRestMethod with don't use -SkipCertifiateCheck" -Skip:("Desktop" -eq $PSEdition) {
Connect-ArubaCP $ipaddress -Token $token
{ Invoke-ArubaCPRestMethod -uri "rest/v4/vlans" } | Should throw "Unable to connect (certificate)"
Disconnect-ArubaCP -noconfirm
}
It "Throw when try to use Invoke-ArubaCPRestMethod and not connected" {
{ Invoke-ArubaCPRestMethod -uri "rest/v4/vlans" } | Should throw "Not Connected. Connect to the ClearPass with Connect-ArubaCP"
}
}

0 comments on commit e3cd72e

Please sign in to comment.