Skip to content

Commit

Permalink
Merge pull request #34 from michaeltlombardi/AddLocalUserTest
Browse files Browse the repository at this point in the history
Add tests for LocalUser
  • Loading branch information
cdhunt authored Sep 12, 2016
2 parents 0291637 + be9443a commit ebb4c83
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Public/LocalUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
.SYNOPSIS
Test if a local user exists and is enabled.
.DESCRIPTION
Test if a local user exists and is enabled.
.PARAMETER Target
The local user name to test for. Eg 'Guest'
.PARAMETER Should
A Script Block defining a Pester Assertion.
.EXAMPLE
LocalGroup 'Guest' { should not BeNullOrEmpty }
.EXAMPLE
LocalGroup 'Guest' Disabled { should Be $true }
.NOTES
Assertions: Be, BeExactly, BeNullOrEmpty, Match, MatchExactly
#>

function LocalUser {
[CmdletBinding(DefaultParameterSetName="Default")]
param(
[Parameter(Mandatory, Position=1,ParameterSetName="Default")]
[Parameter(Mandatory, Position=1,ParameterSetName="Property")]
[Alias('Name')]
[string]$Target,

[Parameter(Position=2,ParameterSetName="Property")]
[string]$Property,

[Parameter(Mandatory, Position=2,ParameterSetName="Default")]
[Parameter(Mandatory, Position=3,ParameterSetName="Property")]
[scriptblock]$Should
)

$expression = {Get-CimInstance -ClassName Win32_UserAccount -filter "LocalAccount=True AND` Name='$Target'"}

$params = Get-PoshspecParam -TestName LocalUser -TestExpression $expression @PSBoundParameters

Invoke-PoshspecExpression @params
}
12 changes: 12 additions & 0 deletions Tests/poshspec.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ Describe 'Test Functions' {
$results.Expression | Should Be "GetAuditPolicy -Category 'System' -Subcategory 'Security System Extension' | Should Be 'Success'"
}
}

Context 'LocalUser' {

$results = LocalUser Guest Disabled { Should Be $True }

It "Should return the correct test Name" {
$results.Name | Should Be "LocalUser property 'Disabled' for 'Guest' Should Be `$True"
}
It "Should return the correct test Expression" {
$results.Expression | Should Be "Get-CimInstance -ClassName Win32_UserAccount -filter `"LocalAccount=True AND Name='Guest'`" | Select-Object -ExpandProperty 'Disabled' | Should Be `$True"
}
}
}
}

Expand Down

0 comments on commit ebb4c83

Please sign in to comment.