Skip to content

Commit

Permalink
Merge pull request #61 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 2.7.0.0 of xWindowsUpdate
  • Loading branch information
kwirkykat authored Jul 12, 2017
2 parents 0d389dd + 2e3e68e commit cd90e80
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function Get-TargetResource
TotalUpdatesNotInstalled = $totalUpdatesNotInstalled
RebootRequired = $rebootRequired
Notifications = $notificationLevel
Service = $SourceReturn
Source = $SourceReturn
UpdateNow = $UpdateNowReturn
}
$returnValue
Expand Down Expand Up @@ -443,7 +443,7 @@ function Set-TargetResource
Write-Verbose "updateNow compliant: $updateCompliant"
$notificationCompliant = (!$Notifications -or $Notifications -eq $Get.Notifications)
Write-Verbose "notifications compliant: $notificationCompliant"
$SourceCompliant = (!$Source -or $Source -eq $Get.Service)
$SourceCompliant = (!$Source -or $Source -eq $Get.Source)
Write-Verbose "service compliant: $notificationCompliant"

If(!$updateCompliant -and $PSCmdlet.ShouldProcess("Install Updates"))
Expand Down Expand Up @@ -549,7 +549,7 @@ function Test-TargetResource
Write-Verbose "updateNow compliant: $updateCompliant"
$notificationCompliant = (!$Notifications -or $Notifications -eq $Get.Notifications)
Write-Verbose "notifications compliant: $notificationCompliant"
$SourceCompliant = (!$Source -or $Source -eq $Get.Service)
$SourceCompliant = (!$Source -or $Source -eq $Get.Source)
Write-Verbose "service compliant: $notificationCompliant"
If($updateCompliant -and $notificationCompliant -and $SourceCompliant)
{
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Please check out common DSC Resources

### Unreleased

### 2.7.0.0

* xWindowsUpdateAgent: Fix Get-TargetResource returning incorrect key

### 2.6.0.0

* Converted appveyor.yml to install Pester from PSGallery instead of from
Expand Down
86 changes: 81 additions & 5 deletions Tests/Unit/MSFT_xWindowsUpdateAgent.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ try
# The InModuleScope command allows you to perform white-box unit testing on the internal
# (non-exported) code of a Script Module.
InModuleScope $Global:DSCResourceName {

#region Pester Test Initialization
$Global:mockedSearchResultWithUpdate = [PSCustomObject] @{
Updates = @{
Expand Down Expand Up @@ -149,8 +149,8 @@ try
it 'should return UpdateNome=$true'{
$getResult.UpdateNow | should be $true
}
it 'should return Service=MU'{
$getResult.Service | should be "MicrosoftUpdate"
it 'should return Source=MU'{
$getResult.Source | should be "MicrosoftUpdate"
}

it 'should have called the mock' {
Expand Down Expand Up @@ -203,8 +203,8 @@ try
it 'should return UpdateNome=$true'{
$getResult.UpdateNow | should be $true
}
it 'should return Service=WU'{
$getResult.Service | should be "WindowsUpdate"
it 'should return Source=WU'{
$getResult.Source | should be "WindowsUpdate"
}

it 'should have called the mock' {
Expand Down Expand Up @@ -1587,6 +1587,82 @@ try
}
}

Describe "$($Global:DSCResourceName)\Test-TargetResourceProperties" {
Mock -CommandName Write-Warning -MockWith {} -Verifiable
Mock -CommandName Write-Verbose -MockWith {}

It 'Calls write-warning when no categories are passed' {
$PropertiesToTest = @{
IsSingleInstance = 'Yes'
Notifications = 'Disabled'
Source = 'WindowsUpdate'
Category = @()
UpdateNow = $True
}
Test-TargetResourceProperties @PropertiesToTest

Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly -Scope It
}

It 'Calls write-warning when Important updates are requested but not Security updates' {
$PropertiesToTest = @{
IsSingleInstance = 'Yes'
Notifications = 'Disabled'
Source = 'WindowsUpdate'
Category = 'Important'
}
Test-TargetResourceProperties @PropertiesToTest

Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly -Scope It
}

It 'Calls write-warning when Optional updates are requested but not Security updates' {
$PropertiesToTest = @{
IsSingleInstance = 'Yes'
Notifications = 'Disabled'
Source = 'WindowsUpdate'
Category = 'Optional'
UpdateNow = $True
}
Test-TargetResourceProperties @PropertiesToTest

Assert-MockCalled -CommandName Write-Verbose -Times 1 -Exactly -Scope It
}

It 'Throws an exception when passed WSUS as a source' {
$PropertiesToTest = @{
IsSingleInstance = 'Yes'
Category = 'Security'
Notifications = 'Disabled'
Source = 'WSUS'
}
{Test-TargetResourceProperties @PropertiesToTest} | Should Throw
}
}

Describe "$($Global:DSCResourceName)\Get-WuaAuNotificationLevelInt" {
It 'Gets int for notification level of Not Configured' {
Get-WuaAuNotificationLevelInt -notificationLevel 'Not Configured' | Should be 0
}
It 'Gets int for notification level of Disabled' {
Get-WuaAuNotificationLevelInt -notificationLevel 'Disabled' | Should be 1
}
It 'Gets int for notification level of Notify before download' {
Get-WuaAuNotificationLevelInt -notificationLevel 'Notify before download' | Should be 2
}
It 'Gets int for notification level of Notify before installation' {
Get-WuaAuNotificationLevelInt -notificationLevel 'Notify before installation' | Should be 3
}
It 'Gets int for notification level of Scheduled Installation' {
Get-WuaAuNotificationLevelInt -notificationLevel 'Scheduled Installation' | Should be 4
}
It 'Gets int for notification level of ScheduledInstallation' {
Get-WuaAuNotificationLevelInt -notificationLevel 'ScheduledInstallation' | Should be 4
}
It 'Gets int for notification level when nothing is provided' {
{ Get-WuaAuNotificationLevelInt } | Should Throw
}
}
}

#endregion
Expand Down
10 changes: 3 additions & 7 deletions xWindowsUpdate.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
# Version number of this module.
ModuleVersion = '2.6.0.0'
ModuleVersion = '2.7.0.0'

# ID used to uniquely identify this module
GUID = 'a9cba250-ea73-4d82-b31b-7e58cc50ffd1'
Expand Down Expand Up @@ -47,12 +47,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Converted appveyor.yml to install Pester from PSGallery instead of from
Chocolatey.
* Fixed PSScriptAnalyzer issues.
* Fixed common test breaks (markdown style, and example style).
* Added CodeCov.io reporting
* Deprecated xMicrosoftUpdate as it"s functionality is replaced by xWindowsUpdateAgent
ReleaseNotes = '* xWindowsUpdateAgent: Fix Get-TargetResource returning incorrect key
'

Expand All @@ -62,3 +57,4 @@ PrivateData = @{
}



0 comments on commit cd90e80

Please sign in to comment.