From 51c6a4b616237b1b104c30e202cac10e1071e5bf Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 17 Mar 2019 10:10:57 +0100 Subject: [PATCH 1/2] Changes to DscResource.Template - Update the integrate test `'Should return $true when Test-DscConfiguration is run'` that did not fail correctly if `Test-DscConfiguration` returned 'False' (issue #14). - Updated some comments in files that wrongly referenced a non-existent module. --- .../en-US/DscResource.Common.strings.psd1 | 2 +- TEMPLATE_README.md | 8 ++++++++ Tests/Integration/MSFT_Folder.Integration.Tests.ps1 | 4 ++-- Tests/Integration/integration_test_template.ps1 | 2 +- Tests/Unit/DscResource.LocalizationHelper.Tests.ps1 | 2 +- Tests/Unit/DscResource.ResourceHelper.Tests.ps1 | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 b/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 index cf5e70b..4739bcf 100644 --- a/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 +++ b/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for helper module CommonResourceHelper. +# Localized resources for helper module DscResource.Common. ConvertFrom-StringData @' PropertyTypeInvalidForDesiredValues = Property 'DesiredValues' must be either a [System.Collections.Hashtable], [CimInstance] or [PSBoundParametersDictionary]. The type detected was {0}. diff --git a/TEMPLATE_README.md b/TEMPLATE_README.md index b237104..1a522a6 100644 --- a/TEMPLATE_README.md +++ b/TEMPLATE_README.md @@ -220,6 +220,14 @@ for more information. This is the change log for DscResource.Template. Any changes to the DscResource.Template should be mentioned here for reference by the users. +### 2019-03-17 + +- Update the integrate test `'Should return $true when Test-DscConfiguration + is run'` that did not fail correctly if `Test-DscConfiguration` returned + 'False' ([issue #14](https://github.com/PowerShell/DscResource.Template/issues/14)). +- Updated some comments in files that wrongly referenced a non-existent + module. + ### 2019-02-03 - Initial commit to repository DscResource.Template. diff --git a/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 b/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 index 7337e0d..4884e9d 100644 --- a/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 @@ -82,7 +82,7 @@ try } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be $true + Test-DscConfiguration -Verbose | Should -Be 'True' } } @@ -133,7 +133,7 @@ try } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be $true + Test-DscConfiguration -Verbose | Should -Be 'True' } } } diff --git a/Tests/Integration/integration_test_template.ps1 b/Tests/Integration/integration_test_template.ps1 index d1a98e0..59866c0 100644 --- a/Tests/Integration/integration_test_template.ps1 +++ b/Tests/Integration/integration_test_template.ps1 @@ -106,7 +106,7 @@ try } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be $true + Test-DscConfiguration -Verbose | Should -Be 'True' } } diff --git a/Tests/Unit/DscResource.LocalizationHelper.Tests.ps1 b/Tests/Unit/DscResource.LocalizationHelper.Tests.ps1 index f278a75..6699d1d 100644 --- a/Tests/Unit/DscResource.LocalizationHelper.Tests.ps1 +++ b/Tests/Unit/DscResource.LocalizationHelper.Tests.ps1 @@ -1,4 +1,4 @@ -# Import the CommonResourceHelper module to test +# Import the DscResource.LocalizationHelper module to test $script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules\DscResource.LocalizationHelper' diff --git a/Tests/Unit/DscResource.ResourceHelper.Tests.ps1 b/Tests/Unit/DscResource.ResourceHelper.Tests.ps1 index 038c2bc..159086b 100644 --- a/Tests/Unit/DscResource.ResourceHelper.Tests.ps1 +++ b/Tests/Unit/DscResource.ResourceHelper.Tests.ps1 @@ -1,4 +1,4 @@ -# Import the CommonResourceHelper module to test +# Import the DscResource.Common module to test $script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules\DscResource.Common' From 3fc62c7b2dc6bc2b6d0d12053b32af0c6f426dde Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 17 Mar 2019 10:20:10 +0100 Subject: [PATCH 2/2] Fix examples to correct template version --- TEMPLATE_README.md | 7 +++--- .../MSFT_Folder.Integration.Tests.ps1 | 24 +++++++++++-------- .../integration_test_template.config.ps1 | 2 +- .../Integration/integration_test_template.ps1 | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/TEMPLATE_README.md b/TEMPLATE_README.md index 1a522a6..d63ff5a 100644 --- a/TEMPLATE_README.md +++ b/TEMPLATE_README.md @@ -222,9 +222,10 @@ DscResource.Template should be mentioned here for reference by the users. ### 2019-03-17 -- Update the integrate test `'Should return $true when Test-DscConfiguration - is run'` that did not fail correctly if `Test-DscConfiguration` returned - 'False' ([issue #14](https://github.com/PowerShell/DscResource.Template/issues/14)). +- Update the integrate test template to version 1.3.3 because the test + `'Should return $true when Test-DscConfiguration is run'` that did not + fail correctly if `Test-DscConfiguration` returned 'False' + ([issue #14](https://github.com/PowerShell/DscResource.Template/issues/14)). - Updated some comments in files that wrongly referenced a non-existent module. diff --git a/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 b/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 index 4884e9d..e0db9da 100644 --- a/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Folder.Integration.Tests.ps1 @@ -11,10 +11,10 @@ if (Test-SkipContinuousIntegrationTask -Type 'Integration') $script:dscModuleName = 'DscResource.Template' $script:dscResourceFriendlyName = 'Folder' -$script:dcsResourceName = "MSFT_$($script:dscResourceFriendlyName)" +$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)" -#region HEADER -# Integration Test Template Version: 1.3.1 +region HEADER +# Integration Test Template Version: 1.3.3 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) @@ -25,17 +25,21 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force $TestEnvironment = Initialize-TestEnvironment ` -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dcsResourceName ` + -DSCResourceName $script:dscResourceName ` -TestType Integration #endregion try { - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" . $configFile - Describe "$($script:DSCResourceName)_Integration" { - $configurationName = "$($script:DSCResourceName)_Create_Config" + Describe "$($script:dscResourceName)_Integration" { + BeforeAll { + $resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test" + } + + $configurationName = "$($script:dscResourceName)_Create_Config" Context ('When using configuration {0}' -f $configurationName) { It 'Should compile and apply the MOF without throwing' { @@ -70,7 +74,7 @@ try It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.Ensure | Should -Be 'Present' @@ -86,7 +90,7 @@ try } } - $configurationName = "$($script:DSCResourceName)_Remove_Config" + $configurationName = "$($script:dscResourceName)_Remove_Config" Context ('When using configuration {0}' -f $configurationName) { It 'Should compile and apply the MOF without throwing' { @@ -121,7 +125,7 @@ try It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.Ensure | Should -Be 'Absent' diff --git a/Tests/Integration/integration_test_template.config.ps1 b/Tests/Integration/integration_test_template.config.ps1 index 43aacfa..6291fdf 100644 --- a/Tests/Integration/integration_test_template.config.ps1 +++ b/Tests/Integration/integration_test_template.config.ps1 @@ -15,7 +15,7 @@ #> #region HEADER -# Integration Test Config Template Version: 1.2.1s +# Integration Test Config Template Version: 1.2.1 #endregion $configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json') diff --git a/Tests/Integration/integration_test_template.ps1 b/Tests/Integration/integration_test_template.ps1 index 59866c0..3ff2312 100644 --- a/Tests/Integration/integration_test_template.ps1 +++ b/Tests/Integration/integration_test_template.ps1 @@ -23,7 +23,7 @@ $script:dscResourceFriendlyName = '' # TODO: Example 'Fire $script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)" # TODO: Update prefix #region HEADER -# Integration Test Template Version: 1.3.2 +# Integration Test Template Version: 1.3.3 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )