Skip to content

Commit

Permalink
UserGroup: Add User Group with no member
Browse files Browse the repository at this point in the history
Add also Tests
  • Loading branch information
alagoutte committed Sep 13, 2024
1 parent 1b0dc2b commit bdf7230
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
18 changes: 10 additions & 8 deletions PowerFGT/Public/cmdb/user/group.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Add-FGTUserGroup {
Param(
[Parameter (Mandatory = $true)]
[string]$name,
[Parameter (Mandatory = $true)]
[Parameter (Mandatory = $false)]
[string[]]$member,
[Parameter (Mandatory = $false)]
[hashtable]$data,
Expand Down Expand Up @@ -63,14 +63,16 @@ function Add-FGTUserGroup {

$usergroup | add-member -name "name" -membertype NoteProperty -Value $name

#Add member to members Array
$members = @( )
foreach ( $m in $member ) {
$member_name = @{ }
$member_name.add( 'name', $m)
$members += $member_name
if ( $PsBoundParameters.ContainsKey('member') ) {
#Add member to members Array
$members = @( )
foreach ( $m in $member ) {
$member_name = @{ }
$member_name.add( 'name', $m)
$members += $member_name
}
$usergroup | add-member -name "member" -membertype NoteProperty -Value $members
}
$usergroup | add-member -name "member" -membertype NoteProperty -Value $members

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
Expand Down
7 changes: 7 additions & 0 deletions Tests/integration/UserGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ Describe "Add User Group" {
Get-FGTUserGroup -name $pester_usergroup1 | Remove-FGTUserGroup -confirm:$false
}

It "Add User Group $pester_usergroup1 (with 0 member)" {
Add-FGTUserGroup -Name $pester_usergroup1
$usergroup = Get-FGTUserGroup -name $pester_usergroup1
$usergroup.name | Should -Be $pester_usergroup1
($usergroup.member).count | Should -Be "0"
}

It "Add User Group $pester_usergroup1 (with 1 member)" {
Add-FGTUserGroup -Name $pester_usergroup1 -member $pester_userlocal
$usergroup = Get-FGTUserGroup -name $pester_usergroup1
Expand Down

0 comments on commit bdf7230

Please sign in to comment.