From 9475909cd4d8f234757438ebb5d8df68ff092acd Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 21 Sep 2020 18:01:46 +1200 Subject: [PATCH] Pin Pester, Convert to DSCResource.Common - Fixes #102, #103 and #105 (#106) --- CHANGELOG.md | 6 + RequiredModules.psd1 | 3 +- build.yaml | 17 +- .../DSC_DFSNamespaceFolder.psm1 | 6 +- .../DSC_DFSNamespaceRoot.psm1 | 6 +- .../DSC_DFSNamespaceServerConfiguration.psm1 | 6 +- .../DSC_DFSReplicationGroup.psm1 | 6 +- .../DSC_DFSReplicationGroupConnection.psm1 | 6 +- .../DSC_DFSReplicationGroupFolder.psm1 | 6 +- .../DSC_DFSReplicationGroupMembership.psm1 | 6 +- .../Modules/DFSDsc.Common/DFSDsc.Common.psm1 | 364 ------------------ .../en-US/DFSDsc.Common.strings.psd1 | 2 - 12 files changed, 37 insertions(+), 397 deletions(-) delete mode 100644 source/Modules/DFSDsc.Common/DFSDsc.Common.psm1 delete mode 100644 source/Modules/DFSDsc.Common/en-US/DFSDsc.Common.strings.psd1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d18920..3e9ae0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 other modules. - Correct case of localization folder names. - Update build badges in `README.md` with correct build IDs. +- DFSDsc + - Updated to use the common module _DscResource.Common_ - Fixes [Issue #102](https://github.com/dsccommunity/DFSDsc/issues/102). + - Fixed build failures caused by changes in `ModuleBuilder` module v1.7.0 + by changing `CopyDirectories` to `CopyPaths` - Fixes [Issue #103](https://github.com/dsccommunity/DFSDsc/issues/103). + - Pin `Pester` module to 4.10.1 because Pester 5.0 is missing code + coverage - Fixes [Issue #105](https://github.com/dsccommunity/DFSDsc/issues/105). ## [4.4.0.0] - 2019-09-19 diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index c26d28d..6fe6eb5 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -9,7 +9,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' - Pester = 'latest' + Pester = '4.10.1' Plaster = 'latest' ModuleBuilder = 'latest' ChangelogManagement = 'latest' @@ -18,5 +18,6 @@ 'DscResource.Test' = 'latest' 'DscResource.AnalyzerRules' = 'latest' 'DscResource.DocGenerator' = 'latest' + 'DscResource.Common' = 'latest' xDscResourceDesigner = 'latest' } diff --git a/build.yaml b/build.yaml index a890f69..4390418 100644 --- a/build.yaml +++ b/build.yaml @@ -2,13 +2,23 @@ #################################################### # ModuleBuilder Configuration # #################################################### -CopyDirectories: +CopyPaths: - en-US - DSCResources - - Modules Encoding: UTF8 VersionedOutputDirectory: true +#################################################### +# ModuleBuilder Dependent Modules Configuration # +#################################################### + +NestedModule: + DscResource.Common: + CopyOnly: true + Path: ./output/RequiredModules/DscResource.Common + AddToManifest: false + Exclude: PSGetModuleInfo.xml + #################################################### # Pipeline Configuration # #################################################### @@ -48,6 +58,7 @@ BuildWorkflow: Pester: OutputFormat: NUnitXML ExcludeFromCodeCoverage: + - Modules/DscResource.Common Script: - tests/Unit ExcludeTag: @@ -60,6 +71,8 @@ DscTest: - 'Common Tests - New Error-Level Script Analyzer Rules' ExcludeSourceFile: - output + ExcludeModuleFile: + - Modules/DscResource.Common Resolve-Dependency: Gallery: 'PSGallery' diff --git a/source/DSCResources/DSC_DFSNamespaceFolder/DSC_DFSNamespaceFolder.psm1 b/source/DSCResources/DSC_DFSNamespaceFolder/DSC_DFSNamespaceFolder.psm1 index 368106b..c76c4ff 100644 --- a/source/DSCResources/DSC_DFSNamespaceFolder/DSC_DFSNamespaceFolder.psm1 +++ b/source/DSCResources/DSC_DFSNamespaceFolder/DSC_DFSNamespaceFolder.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSNamespaceFolder' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS diff --git a/source/DSCResources/DSC_DFSNamespaceRoot/DSC_DFSNamespaceRoot.psm1 b/source/DSCResources/DSC_DFSNamespaceRoot/DSC_DFSNamespaceRoot.psm1 index f3b435d..0289c74 100644 --- a/source/DSCResources/DSC_DFSNamespaceRoot/DSC_DFSNamespaceRoot.psm1 +++ b/source/DSCResources/DSC_DFSNamespaceRoot/DSC_DFSNamespaceRoot.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSNamespaceRoot' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS diff --git a/source/DSCResources/DSC_DFSNamespaceServerConfiguration/DSC_DFSNamespaceServerConfiguration.psm1 b/source/DSCResources/DSC_DFSNamespaceServerConfiguration/DSC_DFSNamespaceServerConfiguration.psm1 index 5342803..c77dce5 100644 --- a/source/DSCResources/DSC_DFSNamespaceServerConfiguration/DSC_DFSNamespaceServerConfiguration.psm1 +++ b/source/DSCResources/DSC_DFSNamespaceServerConfiguration/DSC_DFSNamespaceServerConfiguration.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSNamespaceServerConfiguration' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# This is an array of all the parameters used by this resource. diff --git a/source/DSCResources/DSC_DFSReplicationGroup/DSC_DFSReplicationGroup.psm1 b/source/DSCResources/DSC_DFSReplicationGroup/DSC_DFSReplicationGroup.psm1 index df5b92e..0aa0ab1 100644 --- a/source/DSCResources/DSC_DFSReplicationGroup/DSC_DFSReplicationGroup.psm1 +++ b/source/DSCResources/DSC_DFSReplicationGroup/DSC_DFSReplicationGroup.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSReplicationGroup' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS diff --git a/source/DSCResources/DSC_DFSReplicationGroupConnection/DSC_DFSReplicationGroupConnection.psm1 b/source/DSCResources/DSC_DFSReplicationGroupConnection/DSC_DFSReplicationGroupConnection.psm1 index 3d5cb57..985893f 100644 --- a/source/DSCResources/DSC_DFSReplicationGroupConnection/DSC_DFSReplicationGroupConnection.psm1 +++ b/source/DSCResources/DSC_DFSReplicationGroupConnection/DSC_DFSReplicationGroupConnection.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSReplicationGroupConnection' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS diff --git a/source/DSCResources/DSC_DFSReplicationGroupFolder/DSC_DFSReplicationGroupFolder.psm1 b/source/DSCResources/DSC_DFSReplicationGroupFolder/DSC_DFSReplicationGroupFolder.psm1 index 9da1984..dfa1105 100644 --- a/source/DSCResources/DSC_DFSReplicationGroupFolder/DSC_DFSReplicationGroupFolder.psm1 +++ b/source/DSCResources/DSC_DFSReplicationGroupFolder/DSC_DFSReplicationGroupFolder.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSReplicationGroupFolder' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS diff --git a/source/DSCResources/DSC_DFSReplicationGroupMembership/DSC_DFSReplicationGroupMembership.psm1 b/source/DSCResources/DSC_DFSReplicationGroupMembership/DSC_DFSReplicationGroupMembership.psm1 index 352b1c8..d6298bd 100644 --- a/source/DSCResources/DSC_DFSReplicationGroupMembership/DSC_DFSReplicationGroupMembership.psm1 +++ b/source/DSCResources/DSC_DFSReplicationGroupMembership/DSC_DFSReplicationGroupMembership.psm1 @@ -1,12 +1,10 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the DFSDsc.Common Module -Import-Module -Name (Join-Path -Path $modulePath ` - -ChildPath (Join-Path -Path 'DFSDsc.Common' ` - -ChildPath 'DFSDsc.Common.psm1')) +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'DSC_DFSReplicationGroupMembership' +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS diff --git a/source/Modules/DFSDsc.Common/DFSDsc.Common.psm1 b/source/Modules/DFSDsc.Common/DFSDsc.Common.psm1 deleted file mode 100644 index 2a645a3..0000000 --- a/source/Modules/DFSDsc.Common/DFSDsc.Common.psm1 +++ /dev/null @@ -1,364 +0,0 @@ -<# - .SYNOPSIS - This function tests if a cmdlet exists. - - .PARAMETER Name - The name of the cmdlet to check for. - - .PARAMETER Module - The module containing the command. -#> -function Test-Command -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $Module - ) - - return ($null -ne (Get-Command @PSBoundParameters -ErrorAction SilentlyContinue)) -} # function Test-Command - -<# - .SYNOPSIS - Tests if the current machine is a Nano server. -#> -function Test-IsNanoServer -{ - if (Test-Command -Name 'Get-ComputerInfo' -Module 'Microsoft.PowerShell.Management') - { - $computerInfo = Get-ComputerInfo - - if ('Server' -eq $computerInfo.OsProductType ` - -and 'NanoServer' -eq $computerInfo.OsServerLevel) - { - return $true - } - } - - return $false -} - -<# - .SYNOPSIS - Retrieves the localized string data based on the machine's culture. - Falls back to en-US strings if the machine's culture is not supported. - - .PARAMETER ResourceName - The name of the resource as it appears before '.strings.psd1' of the localized string file. - For example: - For WindowsOptionalFeature: MSFT_WindowsOptionalFeature - For Service: MSFT_ServiceResource - For Registry: MSFT_RegistryResource - For Helper: SqlServerDscHelper - - .PARAMETER ScriptRoot - Optional. The root path where to expect to find the culture folder. This is only needed - for localization in helper modules. This should not normally be used for resources. - - .NOTES - To be able to use localization in the helper function, this function must - be first in the file, before Get-LocalizedData is used by itself to load - localized data for this helper module (see directly after this function). -#> -function Get-LocalizedData -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ResourceName, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String] - $ScriptRoot - ) - - if (-not $ScriptRoot) - { - $dscResourcesFolder = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'DSCResources' - $resourceDirectory = Join-Path -Path $dscResourcesFolder -ChildPath $ResourceName - } - else - { - $resourceDirectory = $ScriptRoot - } - - $localizedStringFileLocation = Join-Path -Path $resourceDirectory -ChildPath $PSUICulture - - if (-not (Test-Path -Path $localizedStringFileLocation)) - { - # Fallback to en-US - $localizedStringFileLocation = Join-Path -Path $resourceDirectory -ChildPath 'en-US' - } - - Import-LocalizedData ` - -BindingVariable 'localizedData' ` - -FileName "$ResourceName.strings.psd1" ` - -BaseDirectory $localizedStringFileLocation - - return $localizedData -} - -<# - .SYNOPSIS - Creates and throws an invalid argument exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ArgumentName - The name of the invalid argument that is causing this error to be thrown. -#> -function New-InvalidArgumentException -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ArgumentName - ) - - $argumentException = New-Object -TypeName 'ArgumentException' ` - -ArgumentList @($Message, $ArgumentName) - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @($argumentException, $ArgumentName, 'InvalidArgument', $null) - } - - $errorRecord = New-Object @newObjectParameters - - throw $errorRecord -} - -<# - .SYNOPSIS - Creates and throws an invalid operation exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. -#> -function New-InvalidOperationException -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $invalidOperationException = New-Object -TypeName 'InvalidOperationException' ` - -ArgumentList @($Message) - } - else - { - $invalidOperationException = New-Object -TypeName 'InvalidOperationException' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $invalidOperationException.ToString(), - 'MachineStateIncorrect', - 'InvalidOperation', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} - -<# - .SYNOPSIS - Creates and throws an object not found exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. -#> -function New-ObjectNotFoundException -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message) - } - else - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $exception.ToString(), - 'MachineStateIncorrect', - 'ObjectNotFound', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} - -<# - .SYNOPSIS - Creates and throws an invalid result exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. -#> -function New-InvalidResultException -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message) - } - else - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $exception.ToString(), - 'MachineStateIncorrect', - 'InvalidResult', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} - -function New-NotImplementedException -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $invalidOperationException = New-Object -TypeName 'NotImplementedException' ` - -ArgumentList @($Message) - } - else - { - $invalidOperationException = New-Object -TypeName 'NotImplementedException' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $invalidOperationException.ToString(), - 'MachineStateIncorrect', - 'NotImplemented', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} - -# Import Localization Strings -$script:localizedData = Get-LocalizedData ` - -ResourceName 'DFSDsc.Common' ` - -ScriptRoot $PSScriptRoot - -Export-ModuleMember -Function @( - 'Test-Command', - 'Test-IsNanoServer', - 'Get-LocalizedData', - 'New-InvalidArgumentException', - 'New-InvalidOperationException', - 'New-ObjectNotFoundException', - 'New-InvalidResultException', - 'New-NotImplementedException' - ) diff --git a/source/Modules/DFSDsc.Common/en-US/DFSDsc.Common.strings.psd1 b/source/Modules/DFSDsc.Common/en-US/DFSDsc.Common.strings.psd1 deleted file mode 100644 index 3b35d66..0000000 --- a/source/Modules/DFSDsc.Common/en-US/DFSDsc.Common.strings.psd1 +++ /dev/null @@ -1,2 +0,0 @@ -ConvertFrom-StringData @' -'@