Skip to content

Commit

Permalink
Zone: add -data parameter with Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alagoutte committed Feb 1, 2024
1 parent 1961d8a commit 14cb6b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions PowerFGT/Public/cmdb/system/zone.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function Add-FGTSystemZone {
[string[]]$interfaces,
[Parameter(Mandatory = $false)]
[string]$description,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -193,6 +195,12 @@ function Add-FGTSystemZone {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$zone | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

Invoke-FGTRestMethod -uri 'api/v2/cmdb/system/zone' -method 'POST' -body $zone -connection $connection @invokeParams | Out-Null
Get-FGTSystemZone -name $name -connection $connection @invokeParams

Expand Down Expand Up @@ -246,6 +254,8 @@ function Set-FGTSystemZone {
[string]$description,
[Parameter(Mandatory = $false)]
[string[]]$interfaces,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -301,6 +311,12 @@ function Set-FGTSystemZone {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$zone_body | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

if ($PSCmdlet.ShouldProcess($zone.name, 'Set zone')) {
Invoke-FGTRestMethod -uri "api/v2/cmdb/system/zone" -uri_escape $zone.name -method 'PUT' -body $zone_body -connection $connection @invokeParams | Out-Null
Get-FGTSystemZone -name $name -connection $connection @invokeParams
Expand Down
17 changes: 17 additions & 0 deletions Tests/integration/SystemZone.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ Describe "Add zone" {
$zone.interface."interface-name" | Should -BeIn $pester_port1, $pester_port2
}

It "Add zone $pester_zone1 with -data" {
$data = @{ 'intrazone' = "allow" }
Add-FGTSystemZone -name $pester_zone1 -interfaces $pester_port1 -data $data
$zone = Get-FGTSystemZone -name $pester_zone1
$zone.name | Should -Be $pester_zone1
$zone.intrazone | Should -Be "allow"
$zone.interface.count | Should -Be 1
$zone.interface."interface-name" | Should -BeIn $pester_port1
}

It "Try to add zone $pester_zone1 (but there is already an object with same name)" {
#Add first zone
Add-FGTSystemZone -name $pester_zone1 -interfaces $pester_port1
Expand Down Expand Up @@ -174,6 +184,13 @@ Describe "Set zone" {
$zone.interface."interface-name" | Should -BeIn $pester_port3, $pester_port4
}

It "Change with -data " {
$data = @{ 'intrazone' = "allow" }
Get-FGTSystemZone -name $pester_zone1 | Set-FGTSystemZone -data $data
$zone = Get-FGTSystemZone -name $pester_zone1
$zone.intrazone | Should -Be "allow"
}

It "Remove interfaces" -Skip:$VersionIs64 {
Get-FGTSystemZone -name $pester_zone1 | Set-FGTSystemZone -interfaces none
$zone = Get-FGTSystemZone -name $pester_zone1
Expand Down

0 comments on commit 14cb6b1

Please sign in to comment.