Skip to content

Commit ebb4c83

Browse files
authored
Merge pull request #34 from michaeltlombardi/AddLocalUserTest
Add tests for LocalUser
2 parents 0291637 + be9443a commit ebb4c83

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Public/LocalUser.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<#
2+
.SYNOPSIS
3+
Test if a local user exists and is enabled.
4+
.DESCRIPTION
5+
Test if a local user exists and is enabled.
6+
.PARAMETER Target
7+
The local user name to test for. Eg 'Guest'
8+
.PARAMETER Should
9+
A Script Block defining a Pester Assertion.
10+
.EXAMPLE
11+
LocalGroup 'Guest' { should not BeNullOrEmpty }
12+
.EXAMPLE
13+
LocalGroup 'Guest' Disabled { should Be $true }
14+
.NOTES
15+
Assertions: Be, BeExactly, BeNullOrEmpty, Match, MatchExactly
16+
#>
17+
18+
function LocalUser {
19+
[CmdletBinding(DefaultParameterSetName="Default")]
20+
param(
21+
[Parameter(Mandatory, Position=1,ParameterSetName="Default")]
22+
[Parameter(Mandatory, Position=1,ParameterSetName="Property")]
23+
[Alias('Name')]
24+
[string]$Target,
25+
26+
[Parameter(Position=2,ParameterSetName="Property")]
27+
[string]$Property,
28+
29+
[Parameter(Mandatory, Position=2,ParameterSetName="Default")]
30+
[Parameter(Mandatory, Position=3,ParameterSetName="Property")]
31+
[scriptblock]$Should
32+
)
33+
34+
$expression = {Get-CimInstance -ClassName Win32_UserAccount -filter "LocalAccount=True AND` Name='$Target'"}
35+
36+
$params = Get-PoshspecParam -TestName LocalUser -TestExpression $expression @PSBoundParameters
37+
38+
Invoke-PoshspecExpression @params
39+
}

Tests/poshspec.Tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,18 @@ Describe 'Test Functions' {
377377
$results.Expression | Should Be "GetAuditPolicy -Category 'System' -Subcategory 'Security System Extension' | Should Be 'Success'"
378378
}
379379
}
380+
381+
Context 'LocalUser' {
382+
383+
$results = LocalUser Guest Disabled { Should Be $True }
384+
385+
It "Should return the correct test Name" {
386+
$results.Name | Should Be "LocalUser property 'Disabled' for 'Guest' Should Be `$True"
387+
}
388+
It "Should return the correct test Expression" {
389+
$results.Expression | Should Be "Get-CimInstance -ClassName Win32_UserAccount -filter `"LocalAccount=True AND Name='Guest'`" | Select-Object -ExpandProperty 'Disabled' | Should Be `$True"
390+
}
391+
}
380392
}
381393
}
382394

0 commit comments

Comments
 (0)