From 03f6ec2bd3b49b724e65330278ab61897d6f0ef5 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Thu, 1 Jun 2017 22:43:42 +1200 Subject: [PATCH 1/4] - Added integration test to test for conflicts with other common resource kit modules. - Prevented ResourceHelper and Common module cmdlets from being exported to resolve conflicts with other resource modules. --- CHANGELOG.md | 3 ++ .../MSFT_xDFSNamespaceFolder.psm1 | 8 ++-- .../MSFT_xDFSNamespaceRoot.psm1 | 8 ++-- ...MSFT_xDFSNamespaceServerConfiguration.psm1 | 8 ++-- .../MSFT_xDFSReplicationGroup.psm1 | 8 ++-- .../MSFT_xDFSReplicationGroupConnection.psm1 | 8 ++-- .../MSFT_xDFSReplicationGroupFolder.psm1 | 8 ++-- .../MSFT_xDFSReplicationGroupMembership.psm1 | 8 ++-- Modules/xDFS/xDFS.psd1 | 2 +- Tests/Integration/ModuleConflict.Tests.ps1 | 47 +++++++++++++++++++ 10 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 Tests/Integration/ModuleConflict.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cfaa48..248fbdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - Fixed xDFSNamespaceServerConfiguration by converting LocalHost to ComputerName instead. +- Added integration test to test for conflicts with other common resource kit modules. +- Prevented ResourceHelper and Common module cmdlets from being exported to resolve + conflicts with other resource modules. ## 3.2.0.0 diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceFolder/MSFT_xDFSNamespaceFolder.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceFolder/MSFT_xDFSNamespaceFolder.psm1 index f2b3230..7888191 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceFolder/MSFT_xDFSNamespaceFolder.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceFolder/MSFT_xDFSNamespaceFolder.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceRoot/MSFT_xDFSNamespaceRoot.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceRoot/MSFT_xDFSNamespaceRoot.psm1 index 053a722..cb21e41 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceRoot/MSFT_xDFSNamespaceRoot.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceRoot/MSFT_xDFSNamespaceRoot.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceServerConfiguration/MSFT_xDFSNamespaceServerConfiguration.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceServerConfiguration/MSFT_xDFSNamespaceServerConfiguration.psm1 index 50c2c99..cd8c171 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceServerConfiguration/MSFT_xDFSNamespaceServerConfiguration.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSNamespaceServerConfiguration/MSFT_xDFSNamespaceServerConfiguration.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroup/MSFT_xDFSReplicationGroup.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroup/MSFT_xDFSReplicationGroup.psm1 index a0daea0..efb6528 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroup/MSFT_xDFSReplicationGroup.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroup/MSFT_xDFSReplicationGroup.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupConnection/MSFT_xDFSReplicationGroupConnection.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupConnection/MSFT_xDFSReplicationGroupConnection.psm1 index 3876d5e..200b424 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupConnection/MSFT_xDFSReplicationGroupConnection.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupConnection/MSFT_xDFSReplicationGroupConnection.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupFolder/MSFT_xDFSReplicationGroupFolder.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupFolder/MSFT_xDFSReplicationGroupFolder.psm1 index 56114c9..1cd1b58 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupFolder/MSFT_xDFSReplicationGroupFolder.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupFolder/MSFT_xDFSReplicationGroupFolder.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupMembership/MSFT_xDFSReplicationGroupMembership.psm1 b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupMembership/MSFT_xDFSReplicationGroupMembership.psm1 index 2cd6264..8258399 100644 --- a/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupMembership/MSFT_xDFSReplicationGroupMembership.psm1 +++ b/Modules/xDFS/DSCResources/MSFT_xDFSReplicationGroupMembership/MSFT_xDFSReplicationGroupMembership.psm1 @@ -1,7 +1,9 @@ -$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' -# Import the xCertificate Resource Module (to import the common modules) -Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xDFS.psd1') +# Import the Certificate Resource Helper Module +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'DFSDsc.ResourceHelper' ` + -ChildPath 'DFSDsc.ResourceHelper.psm1')) # Import Localization Strings $localizedData = Get-LocalizedData ` diff --git a/Modules/xDFS/xDFS.psd1 b/Modules/xDFS/xDFS.psd1 index f1b3a92..0dd6016 100644 --- a/Modules/xDFS/xDFS.psd1 +++ b/Modules/xDFS/xDFS.psd1 @@ -27,7 +27,7 @@ ProcessorArchitecture = 'None' # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess - NestedModules = @('Modules\DFSDsc.ResourceHelper\DFSDsc.ResourceHelper.psm1') + # NestedModules = @() # Functions to export from this module FunctionsToExport = '*' diff --git a/Tests/Integration/ModuleConflict.Tests.ps1 b/Tests/Integration/ModuleConflict.Tests.ps1 new file mode 100644 index 0000000..7466c46 --- /dev/null +++ b/Tests/Integration/ModuleConflict.Tests.ps1 @@ -0,0 +1,47 @@ +$script:DSCModuleName = 'xStorage' +<# + These integration tests ensure that exported cmdlets names do not conflict + with any other names that are exposed by other common resource kit modules. +#> +$script:ModulesToTest = @( 'xNetworking','xComputerManagement','xDFS' ) + +#region HEADER +# Integration 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\xStorage' + +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 'All' ` + -TestType Integration + +#endregion + +# Using try/finally to always cleanup even if something awful happens. +try +{ + Describe "$($script:DSCModuleName)_CommonModuleConflict" { + + foreach ($moduleToTest in $script:ModulesToTest) + { + It "Should be able to install DSC Resource module '$moduleToTest'" { + { + Install-Module -Name $moduleToTest -ErrorAction Stop + } | Should not throw + } + } + } +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} From 5449ebb0e428d790b6d05289847b929ade8863b4 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Thu, 1 Jun 2017 22:47:38 +1200 Subject: [PATCH 2/4] Fix integration tests for module conflicts --- Tests/Integration/ModuleConflict.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Integration/ModuleConflict.Tests.ps1 b/Tests/Integration/ModuleConflict.Tests.ps1 index 7466c46..aa1a06b 100644 --- a/Tests/Integration/ModuleConflict.Tests.ps1 +++ b/Tests/Integration/ModuleConflict.Tests.ps1 @@ -1,9 +1,9 @@ -$script:DSCModuleName = 'xStorage' +$script:DSCModuleName = 'xDFS' <# These integration tests ensure that exported cmdlets names do not conflict with any other names that are exposed by other common resource kit modules. #> -$script:ModulesToTest = @( 'xNetworking','xComputerManagement','xDFS' ) +$script:ModulesToTest = @( 'xNetworking','xComputerManagement' ) #region HEADER # Integration Test Template Version: 1.1.0 From e1ca59cb0842f188ab397355e36cc24b08187cb9 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Thu, 1 Jun 2017 22:51:49 +1200 Subject: [PATCH 3/4] Fix integration tests for module conflicts --- Tests/Integration/ModuleConflict.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Integration/ModuleConflict.Tests.ps1 b/Tests/Integration/ModuleConflict.Tests.ps1 index aa1a06b..5aa33ae 100644 --- a/Tests/Integration/ModuleConflict.Tests.ps1 +++ b/Tests/Integration/ModuleConflict.Tests.ps1 @@ -7,7 +7,7 @@ $script:ModulesToTest = @( 'xNetworking','xComputerManagement' ) #region HEADER # Integration 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\xStorage' +[string] $script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\xDFS' 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'))) ) From 1beddedf591493737a66c036f8f248a5784954c9 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Fri, 2 Jun 2017 08:18:24 +1200 Subject: [PATCH 4/4] Changes as per predictated PR comments --- Tests/Integration/ModuleConflict.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Integration/ModuleConflict.Tests.ps1 b/Tests/Integration/ModuleConflict.Tests.ps1 index 5aa33ae..a475bb5 100644 --- a/Tests/Integration/ModuleConflict.Tests.ps1 +++ b/Tests/Integration/ModuleConflict.Tests.ps1 @@ -34,7 +34,7 @@ try It "Should be able to install DSC Resource module '$moduleToTest'" { { Install-Module -Name $moduleToTest -ErrorAction Stop - } | Should not throw + } | Should Not Throw } } }