mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-13 01:42:28 +00:00
Tests (integration) DCIM (#34)
* Tests: Add Initial support of Integration (using Pester v5) * Site: Add Tests for New/Get/Remove (DCIM) Site
This commit is contained in:
parent
ea75e796ef
commit
d7c008871d
4 changed files with 118 additions and 0 deletions
1
Tests/.gitignore
vendored
Normal file
1
Tests/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
credential.ps1
|
||||||
19
Tests/common.ps1
Normal file
19
Tests/common.ps1
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#
|
||||||
|
# Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
Param()
|
||||||
|
|
||||||
|
$script:pester_site1 = "pester_site1"
|
||||||
|
|
||||||
|
$Credential = New-Object System.Management.Automation.PSCredential("username", (ConvertTo-SecureString $token -AsPlainText -Force))
|
||||||
|
$script:invokeParams = @{
|
||||||
|
hostname = $hostname;
|
||||||
|
Credential = $Credential;
|
||||||
|
SkipCertificateCheck = $true;
|
||||||
|
}
|
||||||
|
|
||||||
|
. ../credential.ps1
|
||||||
|
#TODO: Add check if no ipaddress/token info...
|
||||||
13
Tests/credential.example.ps1
Normal file
13
Tests/credential.example.ps1
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#
|
||||||
|
# Copyright 2021, 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..
|
||||||
|
|
||||||
|
$script:hostname = "10.44.23.213"
|
||||||
|
$script:token = "aaaaaaaaaaaaaaaaaa"
|
||||||
|
|
||||||
|
#Uncomment if you want to personnalize some setting
|
||||||
|
#script:pester_site1 = "pester_site1"
|
||||||
85
Tests/integration/DCIM.Site.Tests.ps1
Normal file
85
Tests/integration/DCIM.Site.Tests.ps1
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
#
|
||||||
|
# Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
. ../common.ps1
|
||||||
|
|
||||||
|
BeforeAll {
|
||||||
|
Connect-NetboxAPI @invokeParams
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe "Get (DCIM) Site" {
|
||||||
|
|
||||||
|
BeforeAll {
|
||||||
|
New-NetboxDCIMSite -name $pester_site1
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get Site Does not throw an error" {
|
||||||
|
{
|
||||||
|
Get-NetboxDCIMSite
|
||||||
|
} | Should -Not -Throw
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get ALL Site" {
|
||||||
|
$site = Get-NetboxDCIMSite
|
||||||
|
$site.count | Should -Not -Be $NULL
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Get Site ($pester_site1)" {
|
||||||
|
$site = Get-NetboxDCIMSite | Where-Object { $_.name -eq $pester_site1 }
|
||||||
|
$site.id | Should -Not -BeNullOrEmpty
|
||||||
|
$site.name | Should -Be $pester_site1
|
||||||
|
$site.status.value | Should -Be "active"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Search Site by name ($pester_site1)" {
|
||||||
|
$site = Get-NetboxDCIMSite -name $pester_site1
|
||||||
|
@($site).count | Should -Be 1
|
||||||
|
$site.id | Should -Not -BeNullOrEmpty
|
||||||
|
$site.name | Should -Be $pester_site1
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterAll {
|
||||||
|
Get-NetboxDCIMSite -name $pester_site1 | Remove-NetboxDCIMSite -confirm:$false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe "New (DCIM) Site" {
|
||||||
|
|
||||||
|
It "New Site with no option" {
|
||||||
|
New-NetboxDCIMSite -name $pester_site1
|
||||||
|
$site = Get-NetboxDCIMSite -name $pester_site1
|
||||||
|
$site.id | Should -Not -BeNullOrEmpty
|
||||||
|
$site.name | Should -Be $pester_site1
|
||||||
|
$site.slug | Should -Be $pester_site1
|
||||||
|
}
|
||||||
|
|
||||||
|
It "New Site with different slug" {
|
||||||
|
New-NetboxDCIMSite -name $pester_site1 -slug pester_slug
|
||||||
|
$site = Get-NetboxDCIMSite -name $pester_site1
|
||||||
|
$site.id | Should -Not -BeNullOrEmpty
|
||||||
|
$site.name | Should -Be $pester_site1
|
||||||
|
$site.slug | Should -Be "pester_slug"
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterEach {
|
||||||
|
Get-NetboxDCIMSite -name $pester_site1 | Remove-NetboxDCIMSite -confirm:$false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe "Remove Site" {
|
||||||
|
|
||||||
|
BeforeEach {
|
||||||
|
New-NetboxDCIMSite -name $pester_site1
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Remove Site" {
|
||||||
|
$site = Get-NetboxDCIMSite -name $pester_site1
|
||||||
|
Remove-NetboxDCIMSite -id $site.id -confirm:$false
|
||||||
|
$site = Get-NetboxDCIMSite -name $pester_site1
|
||||||
|
$site | Should -BeNullOrEmpty
|
||||||
|
@($site).count | Should -Be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue