diff --git a/.vscode/RunAllTests.ps1 b/.vscode/RunAllTests.ps1 deleted file mode 100644 index 2686968..0000000 --- a/.vscode/RunAllTests.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -[string] $repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path) -if ( (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $repoRoot -ChildPath 'Modules\FileContentDsc\DSCResource.Tests\')) -} - -Import-Module (Join-Path -Path $repoRoot -ChildPath 'Tests\TestHarness.psm1' -Resolve) -$dscTestsPath = Join-Path -Path $repoRoot -ChildPath 'Modules\FileContentDsc\DscResource.Tests\Meta.Tests.ps1' -Invoke-TestHarness -DscTestsPath $dscTestsPath diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 86c32f3..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "PowerShell", - "type": "PowerShell", - "request": "launch", - "program": "${file}", - "args": [], - "cwd": "${file}" - }, - { - "name": "Run all tests", - "type": "PowerShell", - "request": "launch", - "program": "${workspaceRoot}/.vscode/RunAllTests.ps1" - } - ] -} diff --git a/CHANGELOG.md b/CHANGELOG.md index ff9bff6..32b878e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Enabled PSSA rule violations to fail build - Fixes [Issue #6](https://github.com/PlagueHO/FileContentDsc/issues/6). - Updated tests to meet Pester v4 standard. - Added Open Code of Conduct. +- Refactored module folder structure to move resource + to root folder of repository and remove test harness - Fixes [Issue #11](https://github.com/PlagueHO/FileContentDsc/issues/11). ## 1.0.0.0 diff --git a/Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.psm1 b/DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.psm1 similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.psm1 rename to DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.psm1 diff --git a/Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.schema.mof b/DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.schema.mof similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.schema.mof rename to DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.schema.mof diff --git a/Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/README.md b/DSCResources/DSR_IniSettingsFile/README.md similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/README.md rename to DSCResources/DSR_IniSettingsFile/README.md diff --git a/Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.schema.mfl b/DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.schema.mfl similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.schema.mfl rename to DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.schema.mfl diff --git a/Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.strings.psd1 b/DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.strings.psd1 similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.strings.psd1 rename to DSCResources/DSR_IniSettingsFile/en-US/DSR_IniSettingsFile.strings.psd1 diff --git a/Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.psm1 b/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.psm1 similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.psm1 rename to DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.psm1 diff --git a/Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.schema.mof b/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.schema.mof similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.schema.mof rename to DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.schema.mof diff --git a/Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/README.md b/DSCResources/DSR_KeyValuePairFile/README.md similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/README.md rename to DSCResources/DSR_KeyValuePairFile/README.md diff --git a/Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.schema.mfl b/DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.schema.mfl similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.schema.mfl rename to DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.schema.mfl diff --git a/Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.strings.psd1 b/DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.strings.psd1 similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.strings.psd1 rename to DSCResources/DSR_KeyValuePairFile/en-US/DSR_KeyValuePairFile.strings.psd1 diff --git a/Modules/FileContentDsc/DSCResources/DSR_ReplaceText/DSR_ReplaceText.psm1 b/DSCResources/DSR_ReplaceText/DSR_ReplaceText.psm1 similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_ReplaceText/DSR_ReplaceText.psm1 rename to DSCResources/DSR_ReplaceText/DSR_ReplaceText.psm1 diff --git a/Modules/FileContentDsc/DSCResources/DSR_ReplaceText/DSR_ReplaceText.schema.mof b/DSCResources/DSR_ReplaceText/DSR_ReplaceText.schema.mof similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_ReplaceText/DSR_ReplaceText.schema.mof rename to DSCResources/DSR_ReplaceText/DSR_ReplaceText.schema.mof diff --git a/Modules/FileContentDsc/DSCResources/DSR_ReplaceText/README.md b/DSCResources/DSR_ReplaceText/README.md similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_ReplaceText/README.md rename to DSCResources/DSR_ReplaceText/README.md diff --git a/Modules/FileContentDsc/DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.schema.mfl b/DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.schema.mfl similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.schema.mfl rename to DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.schema.mfl diff --git a/Modules/FileContentDsc/DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.strings.psd1 b/DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.strings.psd1 similarity index 100% rename from Modules/FileContentDsc/DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.strings.psd1 rename to DSCResources/DSR_ReplaceText/en-US/DSR_ReplaceText.strings.psd1 diff --git a/Modules/FileContentDsc/Examples/Resources/IniSettingsFile/1-IniSettingsFile_SetPlainTextEntry.ps1 b/Examples/Resources/IniSettingsFile/IniSettingsFile_SetPlainTextEntry_Config.ps1 similarity index 74% rename from Modules/FileContentDsc/Examples/Resources/IniSettingsFile/1-IniSettingsFile_SetPlainTextEntry.ps1 rename to Examples/Resources/IniSettingsFile/IniSettingsFile_SetPlainTextEntry_Config.ps1 index a32d087..7899165 100644 --- a/Modules/FileContentDsc/Examples/Resources/IniSettingsFile/1-IniSettingsFile_SetPlainTextEntry.ps1 +++ b/Examples/Resources/IniSettingsFile/IniSettingsFile_SetPlainTextEntry_Config.ps1 @@ -1,20 +1,15 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Set the `Level` entry in the [Logging] section to `Information` in the file `c:\myapp\myapp.ini`. #> Configuration Example { - param - ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost' - ) - Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { IniSettingsFile SetLogging { diff --git a/Modules/FileContentDsc/Examples/Resources/IniSettingsFile/2-IniSettingsFile_SetSecretTextEntry.ps1 b/Examples/Resources/IniSettingsFile/IniSettingsFile_SetSecretTextEntry_Config.ps1 similarity index 84% rename from Modules/FileContentDsc/Examples/Resources/IniSettingsFile/2-IniSettingsFile_SetSecretTextEntry.ps1 rename to Examples/Resources/IniSettingsFile/IniSettingsFile_SetSecretTextEntry_Config.ps1 index d9486e4..598f7e3 100644 --- a/Modules/FileContentDsc/Examples/Resources/IniSettingsFile/2-IniSettingsFile_SetSecretTextEntry.ps1 +++ b/Examples/Resources/IniSettingsFile/IniSettingsFile_SetSecretTextEntry_Config.ps1 @@ -1,5 +1,7 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Set the `ConnectionString` entry in the [Database] section to the password provided in the $Secret credential object in the file `c:\myapp\myapp.ini`. #> @@ -7,10 +9,6 @@ Configuration Example { param ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost', - [Parameter()] [ValidateNotNullorEmpty()] [PSCredential] @@ -19,7 +17,7 @@ Configuration Example Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { IniSettingsFile SetConnectionString { diff --git a/Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/2-KeyValuePairFile_RemovePlainTextPair.ps1 b/Examples/Resources/KeyValuePairFile/KeyValuePairFile_RemovePlainTextPair_Config.ps1 similarity index 71% rename from Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/2-KeyValuePairFile_RemovePlainTextPair.ps1 rename to Examples/Resources/KeyValuePairFile/KeyValuePairFile_RemovePlainTextPair_Config.ps1 index df3c0c5..f46da61 100644 --- a/Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/2-KeyValuePairFile_RemovePlainTextPair.ps1 +++ b/Examples/Resources/KeyValuePairFile/KeyValuePairFile_RemovePlainTextPair_Config.ps1 @@ -1,19 +1,14 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Remove all `Core.Logging` keys in the file `c:\myapp\myapp.conf`. #> Configuration Example { - param - ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost' - ) - Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { KeyValuePairFile RemoveCoreLogging { diff --git a/Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/1-KeyValuePairFile_SetPlainTextPair.ps1 b/Examples/Resources/KeyValuePairFile/KeyValuePairFile_SetPlainTextPair_Config.ps1 similarity index 75% rename from Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/1-KeyValuePairFile_SetPlainTextPair.ps1 rename to Examples/Resources/KeyValuePairFile/KeyValuePairFile_SetPlainTextPair_Config.ps1 index 34440b3..994ac69 100644 --- a/Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/1-KeyValuePairFile_SetPlainTextPair.ps1 +++ b/Examples/Resources/KeyValuePairFile/KeyValuePairFile_SetPlainTextPair_Config.ps1 @@ -1,20 +1,15 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Set all `Core.Logging` keys to `Information` or add it if it is missing in the file `c:\myapp\myapp.conf`. #> Configuration Example { - param - ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost' - ) - Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { KeyValuePairFile SetCoreLogging { diff --git a/Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/3-KeyValuePairFile_SetSecretTextPair.ps1 b/Examples/Resources/KeyValuePairFile/KeyValuePairFile_SetSecretTextPair_Config.ps1 similarity index 84% rename from Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/3-KeyValuePairFile_SetSecretTextPair.ps1 rename to Examples/Resources/KeyValuePairFile/KeyValuePairFile_SetSecretTextPair_Config.ps1 index cb184be..249a40b 100644 --- a/Modules/FileContentDsc/Examples/Resources/KeyValuePairFile/3-KeyValuePairFile_SetSecretTextPair.ps1 +++ b/Examples/Resources/KeyValuePairFile/KeyValuePairFile_SetSecretTextPair_Config.ps1 @@ -1,5 +1,7 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Set all `Core.Password` keys to the password provided in the $Secret credential object or add it if it is missing in the file `c:\myapp\myapp.conf`. #> @@ -7,10 +9,6 @@ Configuration Example { param ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost', - [Parameter()] [ValidateNotNullorEmpty()] [PSCredential] @@ -19,7 +17,7 @@ Configuration Example Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { KeyValuePairFile SetCorePassword { diff --git a/Modules/FileContentDsc/Examples/Resources/ReplaceText/3-ReplaceText_ReplacePlainSecretText.ps1 b/Examples/Resources/ReplaceText/ReplaceText_ReplacePlainSecretText_Config.ps1 similarity index 84% rename from Modules/FileContentDsc/Examples/Resources/ReplaceText/3-ReplaceText_ReplacePlainSecretText.ps1 rename to Examples/Resources/ReplaceText/ReplaceText_ReplacePlainSecretText_Config.ps1 index 747814e..9a4c517 100644 --- a/Modules/FileContentDsc/Examples/Resources/ReplaceText/3-ReplaceText_ReplacePlainSecretText.ps1 +++ b/Examples/Resources/ReplaceText/ReplaceText_ReplacePlainSecretText_Config.ps1 @@ -1,5 +1,7 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Set all occrurances of the string `%secret%` to be the value in the password set in the parameter $Secret PSCredential object in the file `c:\inetpub\wwwroot\default.htm`. @@ -8,10 +10,6 @@ Configuration Example { param ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost', - [Parameter()] [ValidateNotNullorEmpty()] [PSCredential] @@ -20,7 +18,7 @@ Configuration Example Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { ReplaceText SetSecretText { diff --git a/Modules/FileContentDsc/Examples/Resources/ReplaceText/1-ReplaceText_ReplacePlainText.ps1 b/Examples/Resources/ReplaceText/ReplaceText_ReplacePlainText_Config.ps1 similarity index 75% rename from Modules/FileContentDsc/Examples/Resources/ReplaceText/1-ReplaceText_ReplacePlainText.ps1 rename to Examples/Resources/ReplaceText/ReplaceText_ReplacePlainText_Config.ps1 index 8972966..5a272fc 100644 --- a/Modules/FileContentDsc/Examples/Resources/ReplaceText/1-ReplaceText_ReplacePlainText.ps1 +++ b/Examples/Resources/ReplaceText/ReplaceText_ReplacePlainText_Config.ps1 @@ -1,20 +1,15 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE + .DESCRIPTION Set all occrurances of the string `%appname%` to be Awesome App` in the file `c:\inetpub\wwwroot\default.htm`. #> Configuration Example { - param - ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost' - ) - Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { ReplaceText SetText { diff --git a/Modules/FileContentDsc/Examples/Resources/ReplaceText/2-ReplaceText_ReplaceRegexText.ps1 b/Examples/Resources/ReplaceText/ReplaceText_ReplaceRegexText_Config.ps1 similarity index 79% rename from Modules/FileContentDsc/Examples/Resources/ReplaceText/2-ReplaceText_ReplaceRegexText.ps1 rename to Examples/Resources/ReplaceText/ReplaceText_ReplaceRegexText_Config.ps1 index 7157cb2..97ad74b 100644 --- a/Modules/FileContentDsc/Examples/Resources/ReplaceText/2-ReplaceText_ReplaceRegexText.ps1 +++ b/Examples/Resources/ReplaceText/ReplaceText_ReplaceRegexText_Config.ps1 @@ -1,21 +1,16 @@ +#Requires -module FileContentDsc + <# - .EXAMPLE - Set all occrurances of a string matching the regular expression + .DESCRIPTION + Set all occrurances of a string matching the regular expression `` with the text `` in the file `c:\inetpub\wwwroot\default.htm` #> Configuration Example { - param - ( - [Parameter()] - [System.String[]] - $NodeName = 'localhost' - ) - Import-DSCResource -ModuleName FileContentDsc - Node $NodeName + Node localhost { ReplaceText SetTextWithRegex { diff --git a/Modules/FileContentDsc/FileContentDsc.psd1 b/FileContentDsc.psd1 similarity index 100% rename from Modules/FileContentDsc/FileContentDsc.psd1 rename to FileContentDsc.psd1 diff --git a/Modules/FileContentDsc/Modules/FileContentDsc.Common/FileContentDsc.Common.psm1 b/Modules/FileContentDsc.Common/FileContentDsc.Common.psm1 similarity index 100% rename from Modules/FileContentDsc/Modules/FileContentDsc.Common/FileContentDsc.Common.psm1 rename to Modules/FileContentDsc.Common/FileContentDsc.Common.psm1 diff --git a/Modules/FileContentDsc/Modules/FileContentDsc.Common/en-us/FileContentDsc.Common.strings.psd1 b/Modules/FileContentDsc.Common/en-us/FileContentDsc.Common.strings.psd1 similarity index 100% rename from Modules/FileContentDsc/Modules/FileContentDsc.Common/en-us/FileContentDsc.Common.strings.psd1 rename to Modules/FileContentDsc.Common/en-us/FileContentDsc.Common.strings.psd1 diff --git a/Modules/FileContentDsc/Modules/FileContentDsc.ResourceHelper/FileContentDsc.ResourceHelper.psm1 b/Modules/FileContentDsc.ResourceHelper/FileContentDsc.ResourceHelper.psm1 similarity index 100% rename from Modules/FileContentDsc/Modules/FileContentDsc.ResourceHelper/FileContentDsc.ResourceHelper.psm1 rename to Modules/FileContentDsc.ResourceHelper/FileContentDsc.ResourceHelper.psm1 diff --git a/Tests/Integration/DSR_IniSettingsFile.Integration.Tests.ps1 b/Tests/Integration/DSR_IniSettingsFile.Integration.Tests.ps1 index ccc51c7..0ea8bf2 100644 --- a/Tests/Integration/DSR_IniSettingsFile.Integration.Tests.ps1 +++ b/Tests/Integration/DSR_IniSettingsFile.Integration.Tests.ps1 @@ -1,12 +1,26 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') +$script:DSCModuleName = 'FileContentDsc' +$script:DSCResourceName = 'DSR_IniSettingsFile' -$script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'FileContentDsc' ` - -DscResourceName 'DSR_IniSettingsFile' ` - -TestType 'Integration' +#region HEADER +# Integration Test Template Version: 1.1.1 +[System.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'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Integration +#endregion try { @@ -84,8 +98,14 @@ SettingThree=Value3 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose - } | Should -Not -Throw + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop + } | Should -Not -Throw } It 'Should be able to call Get-DscConfiguration without throwing' { @@ -146,7 +166,13 @@ SettingThree=Value3 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop } | Should -Not -Throw } @@ -180,6 +206,7 @@ SettingThree=Value3 } finally { - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - Remove-Module -Name CommonTestHelper + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion } diff --git a/Tests/Integration/DSR_IniSettingsFile.config.ps1 b/Tests/Integration/DSR_IniSettingsFile.config.ps1 index 72fddf3..a72d363 100644 --- a/Tests/Integration/DSR_IniSettingsFile.config.ps1 +++ b/Tests/Integration/DSR_IniSettingsFile.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/DSR_KeyValuePairFile.Integration.Tests.ps1 b/Tests/Integration/DSR_KeyValuePairFile.Integration.Tests.ps1 index 7a98782..cb7b640 100644 --- a/Tests/Integration/DSR_KeyValuePairFile.Integration.Tests.ps1 +++ b/Tests/Integration/DSR_KeyValuePairFile.Integration.Tests.ps1 @@ -1,12 +1,26 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') +$script:DSCModuleName = 'FileContentDsc' +$script:DSCResourceName = 'DSR_KeyValuePairFile' -$script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'FileContentDsc' ` - -DscResourceName 'DSR_KeyValuePairFile' ` - -TestType 'Integration' +#region HEADER +# Integration Test Template Version: 1.1.1 +[System.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'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Integration +#endregion try { @@ -86,7 +100,13 @@ Setting3.Test=Value4 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop } | Should -Not -Throw } @@ -148,7 +168,13 @@ Setting3.Test=Value4 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop } | Should -Not -Throw } @@ -207,7 +233,13 @@ Setting3.Test=Value4 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop } | Should -Not -Throw } @@ -241,6 +273,7 @@ Setting3.Test=Value4 } finally { - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - Remove-Module -Name CommonTestHelper + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion } diff --git a/Tests/Integration/DSR_KeyValuePairFile.config.ps1 b/Tests/Integration/DSR_KeyValuePairFile.config.ps1 index e219ce3..a30af36 100644 --- a/Tests/Integration/DSR_KeyValuePairFile.config.ps1 +++ b/Tests/Integration/DSR_KeyValuePairFile.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/DSR_ReplaceText.Integration.Tests.ps1 b/Tests/Integration/DSR_ReplaceText.Integration.Tests.ps1 index 9e14ed5..acf9be0 100644 --- a/Tests/Integration/DSR_ReplaceText.Integration.Tests.ps1 +++ b/Tests/Integration/DSR_ReplaceText.Integration.Tests.ps1 @@ -1,12 +1,26 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') +$script:DSCModuleName = 'FileContentDsc' +$script:DSCResourceName = 'DSR_ReplaceText' -$script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'FileContentDsc' ` - -DscResourceName 'DSR_ReplaceText' ` - -TestType 'Integration' +#region HEADER +# Integration Test Template Version: 1.1.1 +[System.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'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Integration +#endregion try { @@ -81,7 +95,13 @@ Setting3.Test=Value4 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop } | Should -Not -Throw } @@ -141,7 +161,13 @@ Setting3.Test=Value4 -OutputPath $TestDrive ` -ConfigurationData $configData - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop } | Should -Not -Throw } @@ -174,6 +200,7 @@ Setting3.Test=Value4 } finally { - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - Remove-Module -Name CommonTestHelper + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion } diff --git a/Tests/Integration/DSR_ReplaceText.config.ps1 b/Tests/Integration/DSR_ReplaceText.config.ps1 index 1dbc6a1..4639099 100644 --- a/Tests/Integration/DSR_ReplaceText.config.ps1 +++ b/Tests/Integration/DSR_ReplaceText.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/TestHarness.psm1 b/Tests/TestHarness.psm1 deleted file mode 100644 index 3b92b6f..0000000 --- a/Tests/TestHarness.psm1 +++ /dev/null @@ -1,68 +0,0 @@ -function Invoke-TestHarness -{ - [CmdletBinding()] - param - ( - [System.String] - $TestResultsFile, - - [System.String] - $DscTestsPath - ) - - Write-Verbose -Message 'Commencing all FileContentDsc tests' - - $repoDir = Join-Path -Path $PSScriptRoot -ChildPath '..\' -Resolve - - $testCoverageFiles = @() - Get-ChildItem -Path "$repoDir\modules\FileContentDsc\DSCResources\**\*.psm1" -Recurse | ForEach-Object { - if ($_.FullName -notlike '*\DSCResource.Tests\*') - { - $testCoverageFiles += $_.FullName - } - } - - $testResultSettings = @{ } - if ([String]::IsNullOrEmpty($TestResultsFile) -eq $false) - { - $testResultSettings.Add('OutputFormat', 'NUnitXml' ) - $testResultSettings.Add('OutputFile', $TestResultsFile) - } - - Import-Module -Name "$repoDir\modules\FileContentDsc\FileContentDsc.psd1" - $testsToRun = @() - - # Run Unit Tests - $unitTestsPath = Join-Path -Path $repoDir -ChildPath 'Tests\Unit' - $testsToRun += @( (Get-ChildItem -Path $unitTestsPath).FullName ) - - # Integration Tests - $integrationTestsPath = Join-Path -Path $repoDir -ChildPath 'Tests\Integration' - $testsToRun += @( (Get-ChildItem -Path $integrationTestsPath -Filter '*.Tests.ps1').FullName ) - - # DSC Common Tests - if ($PSBoundParameters.ContainsKey('DscTestsPath') -eq $true) - { - $getChildItemParameters = @{ - Path = $DscTestsPath - Recurse = $true - Filter = '*.Tests.ps1' - } - - # Get all tests '*.Tests.ps1'. - $commonTestFiles = Get-ChildItem @getChildItemParameters - - # Remove DscResource.Tests unit and integration tests. - $commonTestFiles = $commonTestFiles | Where-Object -FilterScript { - $_.FullName -notmatch 'DSCResource.Tests\\Tests' - } - - $testsToRun += @( $commonTestFiles.FullName ) - } - - $results = Invoke-Pester -Script $testsToRun ` - -CodeCoverage $testCoverageFiles ` - -PassThru @testResultSettings - - return $results -} diff --git a/Tests/TestHelpers/CommonTestHelper.psm1 b/Tests/TestHelpers/CommonTestHelper.psm1 index cb2f027..7f20b53 100644 --- a/Tests/TestHelpers/CommonTestHelper.psm1 +++ b/Tests/TestHelpers/CommonTestHelper.psm1 @@ -94,94 +94,8 @@ function Get-InvalidOperationRecord .PARAMETER TestType Specifies whether the test environment will run a Unit test or an Integration test. #> -function Enter-DscResourceTestEnvironment -{ - [OutputType([Hashtable])] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] - $DscResourceModuleName, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] - $DscResourceName, - - [Parameter(Mandatory = $true)] - [ValidateSet('Unit', 'Integration')] - [String] - $TestType - ) - - $testsFolderPath = Split-Path -Path $PSScriptRoot -Parent - $moduleRootPath = Join-Path -Path (Join-Path -Path (Split-Path -Path $testsFolderPath -Parent) -ChildPath 'Modules') -ChildPath 'FileContentDsc' - $dscResourceTestsPath = Join-Path -Path $moduleRootPath -ChildPath 'DSCResource.Tests' - $testHelperFilePath = Join-Path -Path $dscResourceTestsPath -ChildPath 'TestHelper.psm1' - - if (-not (Test-Path -Path $dscResourceTestsPath)) - { - Push-Location $moduleRootPath - git clone 'https://github.com/PowerShell/DscResource.Tests' --quiet - Pop-Location - } - else - { - $gitInstalled = $null -ne (Get-Command -Name 'git' -ErrorAction 'SilentlyContinue') - - if ($gitInstalled) - { - Push-Location $dscResourceTestsPath - git pull origin dev --quiet - Pop-Location - } - else - { - Write-Verbose -Message 'Git not installed. Leaving current DSCResource.Tests as is.' - } - } - - Import-Module -Name $testHelperFilePath - - return Initialize-TestEnvironment ` - -DSCModuleName $DscResourceModuleName ` - -DSCResourceName $DscResourceName ` - -TestType $TestType -} - -<# - .SYNOPSIS - Exits the specified DSC Resource test environment. - - .PARAMETER TestEnvironment - The test environment to exit. -#> -function Exit-DscResourceTestEnvironment -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [Hashtable] - $TestEnvironment - ) - - $testsFolderPath = Split-Path -Path $PSScriptRoot -Parent - $moduleRootPath = Split-Path -Path $testsFolderPath -Parent - $dscResourceTestsPath = Join-Path -Path $moduleRootPath -ChildPath 'DSCResource.Tests' - $testHelperFilePath = Join-Path -Path $dscResourceTestsPath -ChildPath 'TestHelper.psm1' - - Import-Module -Name $testHelperFilePath - - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} Export-ModuleMember -Function ` 'Get-InvalidArgumentRecord', ` - 'Get-InvalidOperationRecord', ` - 'Enter-DscResourceTestEnvironment', ` - 'Exit-DscResourceTestEnvironment' + 'Get-InvalidOperationRecord' diff --git a/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 b/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 index fc015f1..1f2f000 100644 --- a/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 +++ b/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 @@ -1,12 +1,26 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () +$script:DSCModuleName = 'FileContentDsc' +$script:DSCResourceName = 'DSR_IniSettingsFile' + Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global -$script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'FileContentDsc' ` - -DscResourceName 'DSR_IniSettingsFile' ` - -TestType 'Unit' +#region HEADER +# Unit Test Template Version: 1.1.0 +[System.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'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit +#endregion HEADER # Begin Testing try @@ -479,6 +493,7 @@ try } finally { - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - Remove-Module -Name CommonTestHelper + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion } diff --git a/Tests/Unit/DSR_KeyValuePairFile.Tests.ps1 b/Tests/Unit/DSR_KeyValuePairFile.Tests.ps1 index da6dbb6..9927bcf 100644 --- a/Tests/Unit/DSR_KeyValuePairFile.Tests.ps1 +++ b/Tests/Unit/DSR_KeyValuePairFile.Tests.ps1 @@ -1,12 +1,26 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () +$script:DSCModuleName = 'FileContentDsc' +$script:DSCResourceName = 'DSR_KeyValuePairFile' + Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global -$script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'FileContentDsc' ` - -DscResourceName 'DSR_KeyValuePairFile' ` - -TestType 'Unit' +#region HEADER +# Unit Test Template Version: 1.1.0 +[System.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'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit +#endregion HEADER # Begin Testing try @@ -869,6 +883,7 @@ $($script:testAddedName)=$($script:testText) } finally { - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - Remove-Module -Name CommonTestHelper + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion } diff --git a/Tests/Unit/DSR_ReplaceText.Tests.ps1 b/Tests/Unit/DSR_ReplaceText.Tests.ps1 index 73a172b..20435a3 100644 --- a/Tests/Unit/DSR_ReplaceText.Tests.ps1 +++ b/Tests/Unit/DSR_ReplaceText.Tests.ps1 @@ -1,12 +1,26 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () +$script:DSCModuleName = 'FileContentDsc' +$script:DSCResourceName = 'DSR_ReplaceText' + Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global -$script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'FileContentDsc' ` - -DscResourceName 'DSR_ReplaceText' ` - -TestType 'Unit' +#region HEADER +# Unit Test Template Version: 1.1.0 +[System.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'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit +#endregion HEADER # Begin Testing try @@ -500,6 +514,7 @@ Setting3.Test=Value4 } finally { - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - Remove-Module -Name CommonTestHelper + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion } diff --git a/Tests/Unit/FileContentDsc.Common.tests.ps1 b/Tests/Unit/FileContentDsc.Common.tests.ps1 index 2ea92da..c3d002f 100644 --- a/Tests/Unit/FileContentDsc.Common.tests.ps1 +++ b/Tests/Unit/FileContentDsc.Common.tests.ps1 @@ -4,7 +4,7 @@ Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot #region HEADER # Unit Test Template Version: 1.1.0 -[string] $script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\FileContentDsc' +[System.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'))) ) { diff --git a/appveyor.yml b/appveyor.yml index c62641d..9977393 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,11 +3,12 @@ #---------------------------------# version: 1.0.0.{build} install: + # Needed for publishing of examples, build worker defaults to core.autocrlf=input. + - git config --global core.autocrlf true - git clone https://github.com/PowerShell/DscResource.Tests - ps: | $moduleName = 'FileContentDsc' - $mainModuleFolder = "Modules\$moduleName" Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" Invoke-AppveyorInstallTask @@ -24,8 +25,6 @@ build: false test_script: - ps: | Invoke-AppveyorTestScriptTask ` - -Type 'Harness' ` - -MainModulePath $mainModuleFolder ` -CodeCoverage ` -CodeCovIo @@ -38,5 +37,7 @@ deploy_script: - ps: | Invoke-AppveyorAfterTestTask ` -Type 'Wiki' ` - -MainModulePath $mainModuleFolder ` -ResourceModuleName $moduleName + + Invoke-AppVeyorDeployTask ` + -OptIn @()