diff --git a/README.md b/README.md index 83346c576..04ba8b665 100644 --- a/README.md +++ b/README.md @@ -714,13 +714,19 @@ Publishes a 'FileInfo' object(s) to the pullserver configuration repository. It ### Unreleased +* Changes to xPSDesiredStateConfiguration + * In AppVeyor CI the tests are split into three separate jobs, and also + run tests on two different build worker images (Windows Server 2012R2 + and Windows Server 2016). The common tests are only run on the + Windows Server 2016 build worker image. Helps with + [issue #477](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/477). * xWindowsOptionalFeature * Suppress useless verbose output from `Import-Module` cmdlet. ([issue 453](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/453)) * Changes to xRemoteFile * Corrected a resource name in the example xRemoteFile_DownloadFileConfig.ps1 * Fix `MSFT_xDSCWebService` to find `Microsoft.Powershell.DesiredStateConfiguration.Service.Resources.dll` - when server is configured with pt-BR Locales ([issue #284](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/284)). + when server is configured with pt-BR Locales ([issue #284](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/284)). * Changes to xDSCWebService * Fixed an issue which prevented the removal of the IIS Application Pool created during deployment of an DSC Pull Server instance. ([issue #464](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/464)) * Fixed an issue where a Pull Server cannot be deployed on a machine when IIS Express is installed aside a full blown IIS ([issue #191](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/191)) diff --git a/Tests/CommonTestHelper.psm1 b/Tests/CommonTestHelper.psm1 index 7defa6e04..c34dc36c2 100644 --- a/Tests/CommonTestHelper.psm1 +++ b/Tests/CommonTestHelper.psm1 @@ -789,6 +789,47 @@ function Exit-DscResourceTestEnvironment Restore-TestEnvironment -TestEnvironment $TestEnvironment } +<# + .SYNOPSIS + Returns $true if the the environment variable APPVEYOR is set to $true, + and the environment variable CONFIGURATION is set to the value passed + in the parameter Type. + + .PARAMETER Name + Name of the test script that is called. Defaults to the name of the + calling script. + + .PARAMETER Type + Type of tests in the test file. Can be set to Unit or Integration. +#> +function Test-SkipContinuousIntegrationTask +{ + [OutputType([System.Boolean])] + [CmdletBinding()] + param + ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $Name = $MyInvocation.PSCommandPath.Split('\')[-1], + + [Parameter(Mandatory = $true)] + [ValidateSet('Unit', 'Integration')] + [System.String] + $Type + ) + + $result = $false + + if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne $Type) + { + Write-Verbose -Message ('{1} tests in {0} will be skipped unless $env:CONFIGURATION is set to ''{1}''.' -f $Name, $Type) -Verbose + $result = $true + } + + return $result +} + Export-ModuleMember -Function @( 'Test-GetTargetResourceResult', ` 'Wait-ScriptBlockReturnTrue', ` @@ -801,5 +842,6 @@ Export-ModuleMember -Function @( 'Invoke-SetTargetResourceUnitTest', ` 'Invoke-TestTargetResourceUnitTest', ` 'Invoke-ExpectedMocksAreCalledTest', ` - 'Invoke-GenericUnitTest' + 'Invoke-GenericUnitTest', + 'Test-SkipContinuousIntegrationTask' ) diff --git a/Tests/Integration/MSFT_xArchive.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_xArchive.EndToEnd.Tests.ps1 index b47815e87..b181f5e36 100644 --- a/Tests/Integration/MSFT_xArchive.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_xArchive.EndToEnd.Tests.ps1 @@ -1,13 +1,18 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +# Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment +$testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + Describe 'xArchive End to End Tests' { BeforeAll { - # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment - $testsFolderFilePath = Split-Path $PSScriptRoot -Parent - $commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' - Import-Module -Name $commonTestHelperFilePath - $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xArchive' ` diff --git a/Tests/Integration/MSFT_xArchive.Integration.Tests.ps1 b/Tests/Integration/MSFT_xArchive.Integration.Tests.ps1 index 6006eaad8..d423c2d8d 100644 --- a/Tests/Integration/MSFT_xArchive.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xArchive.Integration.Tests.ps1 @@ -1,6 +1,14 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` + -ChildPath 'CommonTestHelper.psm1') + +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + if ($PSVersionTable.PSVersion -lt [Version] '5.1') { Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' @@ -9,11 +17,6 @@ if ($PSVersionTable.PSVersion -lt [Version] '5.1') Describe 'xArchive Integration Tests' { BeforeAll { - # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment - $testsFolderFilePath = Split-Path $PSScriptRoot -Parent - $commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' - Import-Module -Name $commonTestHelperFilePath - $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xArchive' ` diff --git a/Tests/Integration/MSFT_xEnvironmentResource.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_xEnvironmentResource.EndToEnd.Tests.ps1 index 77f585c08..e5364d3b8 100644 --- a/Tests/Integration/MSFT_xEnvironmentResource.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_xEnvironmentResource.EndToEnd.Tests.ps1 @@ -11,6 +11,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xEnvironmentResource' ` diff --git a/Tests/Integration/MSFT_xEnvironmentResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xEnvironmentResource.Integration.Tests.ps1 index e3ec00477..63a80b0ad 100644 --- a/Tests/Integration/MSFT_xEnvironmentResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xEnvironmentResource.Integration.Tests.ps1 @@ -8,6 +8,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xEnvironmentResource' ` diff --git a/Tests/Integration/MSFT_xGroupResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xGroupResource.Integration.Tests.ps1 index 1f657e6e5..48356b4a4 100644 --- a/Tests/Integration/MSFT_xGroupResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xGroupResource.Integration.Tests.ps1 @@ -9,6 +9,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xGroupResource' ` diff --git a/Tests/Integration/MSFT_xMsiPackage.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_xMsiPackage.EndToEnd.Tests.ps1 index 09c870e34..6bc425b33 100644 --- a/Tests/Integration/MSFT_xMsiPackage.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_xMsiPackage.EndToEnd.Tests.ps1 @@ -7,13 +7,18 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +# Import CommonTestHelper +$testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + Describe 'xMsiPackage End to End Tests' { BeforeAll { - # Import CommonTestHelper - $testsFolderFilePath = Split-Path $PSScriptRoot -Parent - $commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' - Import-Module -Name $commonTestHelperFilePath - $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xMsiPackage' ` diff --git a/Tests/Integration/MSFT_xMsiPackage.Integration.Tests.ps1 b/Tests/Integration/MSFT_xMsiPackage.Integration.Tests.ps1 index 9b02c3c0b..0eb2c760d 100644 --- a/Tests/Integration/MSFT_xMsiPackage.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xMsiPackage.Integration.Tests.ps1 @@ -5,6 +5,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $script:testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $script:commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xMsiPackage' ` diff --git a/Tests/Integration/MSFT_xPackageResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xPackageResource.Integration.Tests.ps1 index 622062c57..9e2eb3449 100644 --- a/Tests/Integration/MSFT_xPackageResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xPackageResource.Integration.Tests.ps1 @@ -1,5 +1,10 @@ Import-Module "$PSScriptRoot\..\CommonTestHelper.psm1" +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xPackageResource' ` diff --git a/Tests/Integration/MSFT_xRegistryResource.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_xRegistryResource.EndToEnd.Tests.ps1 index 3fc63dc70..49fafe529 100644 --- a/Tests/Integration/MSFT_xRegistryResource.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_xRegistryResource.EndToEnd.Tests.ps1 @@ -13,6 +13,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xRegistryResource' ` diff --git a/Tests/Integration/MSFT_xRegistryResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xRegistryResource.Integration.Tests.ps1 index 57b2eedb2..022dc581a 100644 --- a/Tests/Integration/MSFT_xRegistryResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xRegistryResource.Integration.Tests.ps1 @@ -13,6 +13,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xRegistryResource' ` diff --git a/Tests/Integration/MSFT_xRemoteFile.Tests.ps1 b/Tests/Integration/MSFT_xRemoteFile.Tests.ps1 index b111877d9..357758ea8 100644 --- a/Tests/Integration/MSFT_xRemoteFile.Tests.ps1 +++ b/Tests/Integration/MSFT_xRemoteFile.Tests.ps1 @@ -1,6 +1,13 @@ +Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` + -ChildPath 'CommonTestHelper.psm1') -$Global:DSCModuleName = 'xPSDesiredStateConfiguration' # Example xNetworking -$Global:DSCResourceName = 'MSFT_xRemoteFile' # Example MSFT_xFirewall +$script:DSCModuleName = 'xPSDesiredStateConfiguration' # Example xNetworking +$script:DSCResourceName = 'MSFT_xRemoteFile' # Example MSFT_xFirewall + +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} #region HEADER # Integration Test Template Version: 1.1.0 @@ -13,26 +20,26 @@ if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $Global:DSCModuleName ` - -DSCResourceName $Global:DSCResourceName ` - -TestType Integration + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Integration #endregion # Using try/finally to always cleanup even if something awful happens. try { #region Integration Tests - $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($Global:DSCResourceName).config.ps1" + $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" . $ConfigFile # Make sure the file to download doesn't exist Remove-Item -Path $TestDestinationPath -Force -ErrorAction SilentlyContinue - Describe "$($Global:DSCResourceName)_Integration" { + Describe "$($script:DSCResourceName)_Integration" { #region DEFAULT TESTS It 'Should compile without throwing' { { - Invoke-Expression -Command "$($Global:DSCResourceName)_Config -OutputPath `$TestDrive" + Invoke-Expression -Command "$($script:DSCResourceName)_Config -OutputPath `$TestDrive" Start-DscConfiguration -Path $TestDrive ` -ComputerName localhost -Wait -Verbose -Force } | Should not throw diff --git a/Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1 index a94199764..123d797bb 100644 --- a/Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1 @@ -6,6 +6,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xScriptResource' ` diff --git a/Tests/Integration/MSFT_xServiceResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xServiceResource.Integration.Tests.ps1 index 8470e1d8e..d089870b2 100644 --- a/Tests/Integration/MSFT_xServiceResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xServiceResource.Integration.Tests.ps1 @@ -15,6 +15,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xServiceResource' ` @@ -116,7 +121,7 @@ try $resourceParameters = $script:existingServiceProperties It 'Should compile and apply the MOF without throwing' { - { + { . $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @resourceParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force @@ -179,7 +184,7 @@ try $resourceParameters = $script:newServiceProperties It 'Should compile and apply the MOF without throwing' { - { + { . $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @resourceParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force @@ -247,7 +252,7 @@ try } It 'Should compile and apply the MOF without throwing' { - { + { . $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @resourceParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force @@ -297,7 +302,7 @@ try } It 'Should compile and apply the MOF without throwing' { - { + { . $script:configurationCredentialOnlyFilePath -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive -ConfigurationData $configData @resourceParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force @@ -342,7 +347,7 @@ try } It 'Should compile and apply the MOF without throwing' { - { + { . $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @resourceParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force @@ -380,7 +385,7 @@ try } It 'Should compile and apply the MOF without throwing' { - { + { . $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @resourceParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force diff --git a/Tests/Integration/MSFT_xUserResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_xUserResource.Integration.Tests.ps1 index 5058e063d..7b3f9e75a 100644 --- a/Tests/Integration/MSFT_xUserResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xUserResource.Integration.Tests.ps1 @@ -1,9 +1,8 @@ <# To run these tests, the currently logged on user must have rights to create a user. - These integration tests cover creating a brand new user, updating values + These integration tests cover creating a brand new user, updating values of a user that already exists, and deleting a user that exists. -#> - +#> # Suppressing this rule since we need to create a plaintext password to test this resource [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () @@ -12,6 +11,11 @@ Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` -ChildPath 'CommonTestHelper.psm1') ` -Force +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xUserResource' ` @@ -34,13 +38,13 @@ try { } ) } - + Context 'Should create a new user' { $configurationName = 'MSFT_xUser_NewUser' $configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName $logPath = Join-Path -Path $TestDrive -ChildPath 'NewUser.log' - + $testUserName = 'TestUserName12345' $testUserPassword = 'StrongOne7.' $testDescription = 'Test Description' @@ -65,7 +69,7 @@ try { It 'Should be able to call Get-DscConfiguration without throwing' { { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw } - + It 'Should return the correct configuration' { $currentConfig = Get-DscConfiguration -Verbose -ErrorAction Stop $currentConfig.UserName | Should Be $testUserName @@ -87,13 +91,13 @@ try { } } } - + Context 'Should update an existing user' { $configurationName = 'MSFT_xUser_UpdateUser' $configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName $logPath = Join-Path -Path $TestDrive -ChildPath 'UpdateUser.log' - + $testUserName = 'TestUserName12345' $testUserPassword = 'StrongOne7.' $testDescription = 'New Test Description' @@ -118,7 +122,7 @@ try { It 'Should be able to call Get-DscConfiguration without throwing' { { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw } - + It 'Should return the correct configuration' { $currentConfig = Get-DscConfiguration -Verbose -ErrorAction Stop $currentConfig.UserName | Should Be $testUserName @@ -140,13 +144,13 @@ try { } } } - + Context 'Should delete an existing user' { $configurationName = 'MSFT_xUser_DeleteUser' $configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName $logPath = Join-Path -Path $TestDrive -ChildPath 'DeleteUser.log' - + $testUserName = 'TestUserName12345' $testUserPassword = 'StrongOne7.' $secureTestPassword = ConvertTo-SecureString $testUserPassword -AsPlainText -Force @@ -170,7 +174,7 @@ try { It 'Should be able to call Get-DscConfiguration without throwing' { { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw } - + It 'Should return the correct configuration' { $currentConfig = Get-DscConfiguration -Verbose -ErrorAction Stop $currentConfig.UserName | Should Be $testUserName @@ -189,7 +193,7 @@ try { } } } - + } } finally diff --git a/Tests/Integration/MSFT_xWindowsFeature.Integration.Tests.ps1 b/Tests/Integration/MSFT_xWindowsFeature.Integration.Tests.ps1 index d0a2635e1..eb87ab1a6 100644 --- a/Tests/Integration/MSFT_xWindowsFeature.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xWindowsFeature.Integration.Tests.ps1 @@ -4,7 +4,6 @@ RSAT-File-Services is set as the feature to test installing/uninstalling a feature with subfeatures. #> - # Suppressing this rule since we need to create a plaintext password to test this resource [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () @@ -13,6 +12,11 @@ Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` -ChildPath 'CommonTestHelper.psm1') ` -Force +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsFeature' ` diff --git a/Tests/Integration/MSFT_xWindowsOptionalFeature.Integration.Tests.ps1 b/Tests/Integration/MSFT_xWindowsOptionalFeature.Integration.Tests.ps1 index c908d2fe2..22ce0b45e 100644 --- a/Tests/Integration/MSFT_xWindowsOptionalFeature.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xWindowsOptionalFeature.Integration.Tests.ps1 @@ -1,5 +1,10 @@ Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'CommonTestHelper.psm1') +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsOptionalFeature' ` diff --git a/Tests/Integration/MSFT_xWindowsPackageCab.Integration.Tests.ps1 b/Tests/Integration/MSFT_xWindowsPackageCab.Integration.Tests.ps1 index cad1fa06d..a393055ae 100644 --- a/Tests/Integration/MSFT_xWindowsPackageCab.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xWindowsPackageCab.Integration.Tests.ps1 @@ -1,5 +1,10 @@ Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'CommonTestHelper.psm1') +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsPackageCab' ` diff --git a/Tests/Integration/MSFT_xWindowsProcess.Integration.Tests.ps1 b/Tests/Integration/MSFT_xWindowsProcess.Integration.Tests.ps1 index 12d14614c..ffe5f8a25 100644 --- a/Tests/Integration/MSFT_xWindowsProcess.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_xWindowsProcess.Integration.Tests.ps1 @@ -13,6 +13,11 @@ Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` -ChildPath 'CommonTestHelper.psm1') ` -Force +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsProcess' ` diff --git a/Tests/Integration/xGroupSet.Integration.Tests.ps1 b/Tests/Integration/xGroupSet.Integration.Tests.ps1 index 5577c34ae..da906896d 100644 --- a/Tests/Integration/xGroupSet.Integration.Tests.ps1 +++ b/Tests/Integration/xGroupSet.Integration.Tests.ps1 @@ -9,6 +9,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'xGroupSet' ` diff --git a/Tests/Integration/xProcessSet.Integration.Tests.ps1 b/Tests/Integration/xProcessSet.Integration.Tests.ps1 index 310fa145e..962fd5f19 100644 --- a/Tests/Integration/xProcessSet.Integration.Tests.ps1 +++ b/Tests/Integration/xProcessSet.Integration.Tests.ps1 @@ -6,6 +6,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'xProcessSet' ` diff --git a/Tests/Integration/xServiceSet.Integration.Tests.ps1 b/Tests/Integration/xServiceSet.Integration.Tests.ps1 index 2fe6e0c2c..2ff9b0968 100644 --- a/Tests/Integration/xServiceSet.Integration.Tests.ps1 +++ b/Tests/Integration/xServiceSet.Integration.Tests.ps1 @@ -15,6 +15,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'xServiceSet' ` diff --git a/Tests/Integration/xWindowsFeatureSet.Integration.Tests.ps1 b/Tests/Integration/xWindowsFeatureSet.Integration.Tests.ps1 index d4c94f77d..781f3fa73 100644 --- a/Tests/Integration/xWindowsFeatureSet.Integration.Tests.ps1 +++ b/Tests/Integration/xWindowsFeatureSet.Integration.Tests.ps1 @@ -6,6 +6,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'xWindowsFeatureSet' ` diff --git a/Tests/Integration/xWindowsOptionalFeatureSet.Integration.Tests.ps1 b/Tests/Integration/xWindowsOptionalFeatureSet.Integration.Tests.ps1 index 46899f142..4814dcc2a 100644 --- a/Tests/Integration/xWindowsOptionalFeatureSet.Integration.Tests.ps1 +++ b/Tests/Integration/xWindowsOptionalFeatureSet.Integration.Tests.ps1 @@ -6,6 +6,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Integration') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'xWindowsOptionalFeatureSet' ` diff --git a/Tests/Unit/CommonResourceHelper.Tests.ps1 b/Tests/Unit/CommonResourceHelper.Tests.ps1 index d04c594ed..3378d3a1b 100644 --- a/Tests/Unit/CommonResourceHelper.Tests.ps1 +++ b/Tests/Unit/CommonResourceHelper.Tests.ps1 @@ -1,6 +1,15 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + Describe 'CommonResourceHelper Unit Tests' { BeforeAll { # Import the CommonResourceHelper module to test diff --git a/Tests/Unit/MSFT_xArchive.Tests.ps1 b/Tests/Unit/MSFT_xArchive.Tests.ps1 index f81acbbfb..0e4dc6eb2 100644 --- a/Tests/Unit/MSFT_xArchive.Tests.ps1 +++ b/Tests/Unit/MSFT_xArchive.Tests.ps1 @@ -1,6 +1,15 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + Describe 'xArchive Unit Tests' { BeforeAll { # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment diff --git a/Tests/Unit/MSFT_xDSCWebService.Tests.ps1 b/Tests/Unit/MSFT_xDSCWebService.Tests.ps1 index b19c0fc88..e9721a287 100644 --- a/Tests/Unit/MSFT_xDSCWebService.Tests.ps1 +++ b/Tests/Unit/MSFT_xDSCWebService.Tests.ps1 @@ -1,6 +1,15 @@ +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + $script:dscModuleName = 'xPSDesiredStateConfiguration' $script:dscResourceName = 'MSFT_xDSCWebService' +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + #region HEADER # Integration Test Template Version: 1.1.0 [String] $script:moduleRoot = Split-Path -Parent -Path (Split-Path -Parent -Path $PSScriptRoot) diff --git a/Tests/Unit/MSFT_xEnvironmentResource.Tests.ps1 b/Tests/Unit/MSFT_xEnvironmentResource.Tests.ps1 index c605e463a..1765b3afb 100644 --- a/Tests/Unit/MSFT_xEnvironmentResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xEnvironmentResource.Tests.ps1 @@ -1,6 +1,15 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' diff --git a/Tests/Unit/MSFT_xGroupResource.Tests.ps1 b/Tests/Unit/MSFT_xGroupResource.Tests.ps1 index ddb20e07b..2f5d62ffb 100644 --- a/Tests/Unit/MSFT_xGroupResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xGroupResource.Tests.ps1 @@ -9,6 +9,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xGroupResource' ` @@ -114,7 +119,7 @@ try It 'Should return output Get-TargetResourceOnFullSKU with all parameters when not on Nano Server' { $getTargetResourceResult = Get-TargetResource -GroupName $script:testGroupName -Credential $script:testCredential - + Assert-MockCalled -CommandName 'Test-IsNanoServer' Assert-MockCalled -CommandName 'Get-TargetResourceOnFullSKU' -ParameterFilter { $GroupName -eq $script:testGroupName -and $Credential -eq $script:testCredential } $getTargetResourceResult.TestResult | Should Be 'OnFullSKU' @@ -122,9 +127,9 @@ try It 'Should call Get-TargetResourceOnNanoServer with all parameters when on Nano Server' { Mock -CommandName 'Test-IsNanoServer' -MockWith { return $true } - + $getTargetResourceResult = Get-TargetResource -GroupName $script:testGroupName -Credential $script:testCredential - + Assert-MockCalled -CommandName 'Test-IsNanoServer' Assert-MockCalled -CommandName 'Get-TargetResourceOnNanoServer' -ParameterFilter { $GroupName -eq $script:testGroupName -and $Credential -eq $script:testCredential } $getTargetResourceResult.TestResult | Should Be 'OnNanoServer' @@ -144,16 +149,16 @@ try It 'Should call Set-TargetResourceOnFullSKU with all parameters when not on Nano Server' { Set-TargetResource -GroupName $script:testGroupName -Credential $script:testCredential - + Assert-MockCalled -CommandName 'Test-IsNanoServer' Assert-MockCalled -CommandName 'Set-TargetResourceOnFullSKU' -ParameterFilter { $GroupName -eq $script:testGroupName -and $Credential -eq $script:testCredential } } It 'Should call Set-TargetResourceOnNanoServer with all parameters when on Nano Server' { Mock -CommandName 'Test-IsNanoServer' -MockWith { return $true } - + Set-TargetResource -GroupName $script:testGroupName -Credential $script:testCredential - + Assert-MockCalled -CommandName 'Test-IsNanoServer' Assert-MockCalled -CommandName 'Set-TargetResourceOnNanoServer' -ParameterFilter { $GroupName -eq $script:testGroupName -and $Credential -eq $script:testCredential } } @@ -172,16 +177,16 @@ try It 'Should call Test-TargetResourceOnFullSKU with all parameters when not on Nano Server' { $testTargetResourceResult = Test-TargetResource -GroupName $script:testGroupName -Credential $script:testCredential - + Assert-MockCalled -CommandName 'Test-IsNanoServer' Assert-MockCalled -CommandName 'Test-TargetResourceOnFullSKU' -ParameterFilter { $GroupName -eq $script:testGroupName -and $Credential -eq $script:testCredential } } It 'Should call Test-TargetResourceOnNanoServer with all parameters when on Nano Server' { Mock -CommandName 'Test-IsNanoServer' -MockWith { return $true } - + $testTargetResourceResult = Test-TargetResource -GroupName $script:testGroupName -Credential $script:testCredential - + Assert-MockCalled -CommandName 'Test-IsNanoServer' Assert-MockCalled -CommandName 'Test-TargetResourceOnNanoServer' -ParameterFilter { $GroupName -eq $script:testGroupName -and $Credential -eq $script:testCredential } } @@ -189,7 +194,7 @@ try Context 'Assert-GroupNameValid' { $invalidCharacters = @( '\', '/', '"', '[', ']', ':', '|', '<', '>', '+', '=', ';', ',', '?', '*', '@' ) - + foreach ($invalidCharacter in $invalidCharacters) { It "Should throw error if name contains invalid character '$invalidCharacter'" { @@ -221,7 +226,7 @@ try Context 'Test-IsLocalMachine' { Mock -CommandName 'Get-CimInstance' -MockWith { } - + $localMachineScopes = @( '.', $env:computerName, 'localhost', '127.0.0.1' ) foreach ($localMachineScope in $localMachineScopes) @@ -239,7 +244,7 @@ try It 'Should return true if custom local IP address provided and Get-CimInstance contains matching IP address' { Mock -CommandName 'Get-CimInstance' -MockWith { return @{ IPAddress = @($customLocalIPAddress, '789.1.2.3')} } - + Test-IsLocalMachine -Scope $customLocalIPAddress | Should Be $true } @@ -308,12 +313,12 @@ try $testMembers = @('User1', 'User2') Mock -CommandName 'Get-MembersOnNanoServer' -MockWith { return @() } - + It 'Should return Ensure as Absent when Get-LocalGroup throws a GroupNotFound exception' { Mock -CommandName 'Get-LocalGroup' -MockWith { Write-Error -Message 'Test error message' -CategoryReason 'GroupNotFoundException' } - + $getTargetResourceResult = Get-TargetResourceOnNanoServer -GroupName $script:testGroupName - + Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } $getTargetResourceResult -is [Hashtable] | Should Be $true @@ -324,17 +329,17 @@ try It 'Should throw an error when Get-LocalGroup throws an exception other than GroupNotFound' { Mock -CommandName 'Get-LocalGroup' -MockWith { Write-Error -Message $script:testErrorMessage -CategoryReason 'OtherException' } - + { $getTargetResourceResult = Get-TargetResourceOnNanoServer -GroupName $script:testGroupName } | Should Throw $script:testErrorMessage - + Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } } It 'Should return correct hashtable values when Get-LocalGroup returns a valid, existing group without members' { $script:testLocalGroup.Description = $script:testGroupDescription - + Mock -CommandName 'Get-LocalGroup' -MockWith { return $script:testLocalGroup } - + $getTargetResourceResult = Get-TargetResourceOnNanoServer -GroupName $script:testGroupName Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } @@ -350,12 +355,12 @@ try It 'Should return correct hashtable values when Get-LocalGroup returns a valid, existing group with members' { $script:testLocalGroup.Description = $script:testGroupDescription - + Mock -CommandName 'Get-LocalGroup' -MockWith { return $script:testLocalGroup } Mock -CommandName 'Get-MembersOnNanoServer' -MockWith { return $testMembers } - + $getTargetResourceResult = Get-TargetResourceOnNanoServer -GroupName $script:testGroupName - + Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } Assert-MockCalled -CommandName 'Get-MembersOnNanoServer' -ParameterFilter { $Group -eq $script:testLocalGroup } @@ -376,7 +381,7 @@ try Mock -CommandName 'Get-MembersOnNanoServer' -MockWith { } Mock -CommandName 'Add-LocalGroupMember' -MockWith { } Mock -CommandName 'Remove-LocalGroupMember' -MockWith { } - + It 'Should not attempt to remove an absent group when Ensure is Absent' { Set-TargetResourceOnNanoServer -GroupName $script:testGroupName -Ensure 'Absent' @@ -529,7 +534,7 @@ try It 'Should remove a member from an existing group using MembersToExclude' { $testMembers = @( $script:testMemberName2 ) - + Set-TargetResourceOnNanoServer -GroupName $script:testGroupName -MembersToExclude $testMembers -Ensure 'Present' Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } @@ -660,13 +665,13 @@ try Context 'Test-TargetResourceOnNanoServer' { Mock -CommandName 'Get-LocalGroup' -MockWith { Write-Error -Message 'Test error message' -CategoryReason 'GroupNotFoundException' } Mock -CommandName 'Get-MembersOnNanoServer' -MockWith { } - + It 'Should return true for an absent group when Ensure is Absent' { Test-TargetResourceOnNanoServer -GroupName $script:testGroupName -Ensure 'Absent' | Should Be $true Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } } - + It 'Should return false for an absent group when Ensure is Present' { Test-TargetResourceOnNanoServer -GroupName $script:testGroupName -Ensure 'Present' | Should Be $false @@ -695,7 +700,7 @@ try It 'Should return true for an existing group with a matching description' { $script:testLocalGroup.Description = $script:testGroupDescription - + Test-TargetResourceOnNanoServer -GroupName $script:testGroupName -Description $script:testGroupDescription -Ensure 'Present' | Should Be $true Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } @@ -703,7 +708,7 @@ try It 'Should return false for an existing group with a mismatching description' { $script:testLocalGroup.Description = $script:testGroupDescription - + Test-TargetResourceOnNanoServer -GroupName $script:testGroupName -Description 'Wrong description' -Ensure 'Present' | Should Be $false Assert-MockCalled -CommandName 'Get-LocalGroup' -ParameterFilter { $Name -eq $script:testGroupName } @@ -847,10 +852,10 @@ try Mock -CommandName 'Get-Group' -MockWith { } Mock -CommandName 'Get-MembersOnFullSKU' -MockWith { return @() } Mock -CommandName 'Remove-DisposableObject' -MockWith { } - + It 'Should return Ensure as Absent when Get-Group returns null' { $getTargetResourceResult = Get-TargetResourceOnFullSKU -GroupName $script:testGroupName - + Assert-MockCalled -CommandName 'Get-Group' -ParameterFilter { $GroupName -eq $script:testGroupName } Assert-MockCalled -CommandName 'Remove-DisposableObject' @@ -862,9 +867,9 @@ try It 'Should return correct hashtable values when Get-Group returns a valid, existing group without members' { $script:testGroup.Description = $script:testGroupDescription - + Mock -CommandName 'Get-Group' -MockWith { return $script:testGroup } - + $getTargetResourceResult = Get-TargetResourceOnFullSKU -GroupName $script:testGroupName Assert-MockCalled -CommandName 'Get-Group' -ParameterFilter { $GroupName -eq $script:testGroupName } @@ -881,12 +886,12 @@ try It 'Should return correct hashtable values when Get-Group returns a valid, existing group with members' { $testGroup.Description = $script:testGroupDescription - + Mock -CommandName 'Get-Group' -MockWith { return $script:testGroup } Mock -CommandName 'Get-MembersOnFullSKU' -MockWith { return $testMembers } - + $getTargetResourceResult = Get-TargetResourceOnFullSKU -GroupName $script:testGroupName - + Assert-MockCalled -CommandName 'Get-Group' -ParameterFilter { $GroupName -eq $script:testGroupName } Assert-MockCalled -CommandName 'Get-MembersOnFullSKU' -ParameterFilter { $Group -eq $script:testGroup } Assert-MockCalled -CommandName 'Remove-DisposableObject' @@ -903,36 +908,36 @@ try Context 'Set-TargetResourceOnFullSKU' { Mock -CommandName 'Get-Group' -MockWith { } Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { } - Mock -CommandName 'ConvertTo-UniquePrincipalsList' -MockWith { + Mock -CommandName 'ConvertTo-UniquePrincipalsList' -MockWith { $memberPrincipals = @() if ($MemberNames -contains $script:testUserPrincipal1.Name) { $memberPrincipals += @( $script:testUserPrincipal1` ) } - + if ($MemberNames -contains $script:testUserPrincipal2.Name) { $memberPrincipals += @( $script:testUserPrincipal2 ) } - + if ($MemberNames -contains $script:testUserPrincipal3.Name) { $memberPrincipals += @( $script:testUserPrincipal3 ) } return $memberPrincipals - } - + } + Mock -CommandName 'Clear-GroupMembers' -MockWith { } Mock -CommandName 'Add-GroupMember' -MockWith { } Mock -CommandName 'Remove-GroupMember' -MockWith { } Mock -CommandName 'Remove-Group' -MockWith { } Mock -CommandName 'Save-Group' -MockWith { } - + Mock -CommandName 'Remove-DisposableObject' -MockWith { } Mock -CommandName 'Get-PrincipalContext' -MockWith { return $script:testPrincipalContext } - + It 'Should not attempt to remove an absent group when Ensure is Absent' { Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Ensure 'Absent' @@ -941,7 +946,7 @@ try Assert-MockCalled -CommandName 'Remove-Group' -ParameterFilter { $Group.Name -eq $script:testGroupName } -Times 0 -Scope 'It' Assert-MockCalled -CommandName 'Remove-DisposableObject' -Scope 'It' } - + It 'Should create an empty group' { Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Ensure 'Present' @@ -962,7 +967,7 @@ try It 'Should create a group with one local member using Members' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.GroupPrincipal' } -MockWith { return $testGroup } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -978,8 +983,8 @@ try It 'Should create a group with two local members using Members' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - - Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.GroupPrincipal' } -MockWith { return $testGroup } + + Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.GroupPrincipal' } -MockWith { return $testGroup } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -995,7 +1000,7 @@ try It 'Should create a group with one local member using MembersToInclude' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.GroupPrincipal' } -MockWith { return $testGroup } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -Ensure 'Present' @@ -1011,7 +1016,7 @@ try It 'Should create a group with two local members using MembersToInclude' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - + Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.GroupPrincipal' } -MockWith { return $testGroup } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -Ensure 'Present' @@ -1030,7 +1035,7 @@ try It 'Should add a member to an existing group with no members using Members' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @() } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1046,7 +1051,7 @@ try It 'Should add two members to an existing group with one of the members using Members' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1063,7 +1068,7 @@ try It 'Should add a member to an existing group with no members using MembersToInclude' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @() } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -Ensure 'Present' @@ -1079,7 +1084,7 @@ try It 'Should add two members to an existing group with one of the members using MembersToInclude' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -Ensure 'Present' @@ -1096,7 +1101,7 @@ try It 'Should remove a member from an existing group using Members' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1112,7 +1117,7 @@ try It 'Should clear group members from an existing group using Members' { $testMembers = @( ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1127,7 +1132,7 @@ try It 'Should remove a member from an existing group using MembersToExclude' { $testMembers = @( $script:testUserPrincipal2.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToExclude $testMembers -Ensure 'Present' @@ -1143,7 +1148,7 @@ try It 'Should add a user and remove a user using Members' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal3.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1161,9 +1166,9 @@ try It 'Should add a user and remove a user using MembersToInclude and MembersToExclude at the same time' { $testMembersToInclude = @( $script:testUserPrincipal3.Name ) $testMembersToExclude = @( $script:testUserPrincipal2.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } - + Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembersToInclude -MembersToExclude $testMembersToExclude -Ensure 'Present' Assert-MockCalled -CommandName 'Get-PrincipalContext' @@ -1206,8 +1211,8 @@ try It 'Should not modify group if member specified by MembersToInclude is already in group' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - - Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } + + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -Ensure 'Present' @@ -1220,7 +1225,7 @@ try It 'Should not modify group if member specified by MembersToExclude is not in group' { $testMembers = @( $script:testUserPrincipal3.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToExclude $testMembers -Ensure 'Present' @@ -1234,7 +1239,7 @@ try It 'Should not modify group if members specified by Members match group members' { $testMembers = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1248,7 +1253,7 @@ try It 'Should not modify group if MembersToInclude is empty' { $testMembers = @( ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -Ensure 'Present' @@ -1276,7 +1281,7 @@ try It 'Should not modify group if both MembersToInclude and MembersToExclude are empty' { $testMembers = @( ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @( ) } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembers -MembersToExclude $testMembers -Ensure 'Present' @@ -1290,7 +1295,7 @@ try It 'Should not modify group with no members if Members is empty' { $testMembers = @( ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Ensure 'Present' @@ -1322,7 +1327,7 @@ try It 'Should pass Credential to all appropriate functions when using Members' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @() } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Credential $script:testCredential -Ensure 'Present' @@ -1333,7 +1338,7 @@ try It 'Should pass Credential to all appropriate functions when using MembersToInclude and MembersToExclude' { $testMembers = @( $script:testUserPrincipal1.Name ) - + Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { return @() } Set-TargetResourceOnFullSKU -GroupName $script:testGroupName -Members $testMembers -Credential $script:testCredential -Ensure 'Present' @@ -1348,19 +1353,19 @@ try Context 'Test-TargetResourceOnFullSKU' { Mock -CommandName 'Get-Group' -MockWith { } Mock -CommandName 'Get-MembersAsPrincipalsList' -MockWith { } - Mock -CommandName 'ConvertTo-UniquePrincipalsList' -MockWith { + Mock -CommandName 'ConvertTo-UniquePrincipalsList' -MockWith { $memberPrincipals = @() if ($MemberNames -contains $script:testUserPrincipal1.Name) { $memberPrincipals += @( $script:testUserPrincipal1` ) } - + if ($MemberNames -contains $script:testUserPrincipal2.Name) { $memberPrincipals += @( $script:testUserPrincipal2 ) } - + if ($MemberNames -contains $script:testUserPrincipal3.Name) { $memberPrincipals += @( $script:testUserPrincipal3 ) @@ -1368,10 +1373,10 @@ try return $memberPrincipals } - + Mock -CommandName 'Remove-DisposableObject' -MockWith { } Mock -CommandName 'Get-PrincipalContext' -MockWith { return $script:testPrincipalContext } - + It 'Should return true for an absent group when Ensure is Absent' { Test-TargetResourceOnFullSKU -GroupName $script:testGroupName -Ensure 'Absent' | Should Be $true @@ -1379,7 +1384,7 @@ try Assert-MockCalled -CommandName 'Get-Group' -ParameterFilter { $GroupName -eq $script:testGroupName } -Scope 'It' Assert-MockCalled -CommandName 'Remove-DisposableObject' } - + It 'Should return false for an absent group when Ensure is Present' { Test-TargetResourceOnFullSKU -GroupName $script:testGroupName -Ensure 'Present' | Should Be $false @@ -1408,7 +1413,7 @@ try It 'Should return true for an existing group with a matching description' { $script:testGroup.Description = $script:testGroupDescription - + Test-TargetResourceOnFullSKU -GroupName $script:testGroupName -Description $script:testGroupDescription -Ensure 'Present' | Should Be $true Assert-MockCalled -CommandName 'Get-PrincipalContext' @@ -1418,7 +1423,7 @@ try It 'Should return false for an existing group with a mismatching description' { $script:testGroup.Description = $script:testGroupDescription - + Test-TargetResourceOnFullSKU -GroupName $script:testGroupName -Description 'Wrong description' -Ensure 'Present' | Should Be $false Assert-MockCalled -CommandName 'Get-PrincipalContext' @@ -1561,7 +1566,7 @@ try { Test-TargetResourceOnFullSKU -GroupName $script:testGroupName -MembersToInclude $testMembersToInclude -MembersToExclude $testMembersToExclude -Ensure 'Present' } | Should Throw $errorMessage } } - + Context 'Get-MembersOnFullSKU' { $principalContextCache = @{} $disposables = New-Object -TypeName 'System.Collections.ArrayList' @@ -1613,7 +1618,7 @@ try $expectedGetMembersResult = @( $expectedName1, $expectedName2 ) $getMembersResult = Get-MembersOnFullSKU -Group $script:testGroup -PrincipalContextCache $principalContextCache -Disposables $disposables - + (Compare-Object -ReferenceObject $expectedGetMembersResult -DifferenceObject $getMembersResult) | Should Be $null Assert-MockCalled -CommandName 'Get-MembersAsPrincipalsList' -ParameterFilter { $Group.Name -eq $script:testGroupName } @@ -1623,16 +1628,16 @@ try Context 'Get-MembersAsPrincipalsList' { $principalContextCache = @{} $disposables = New-Object -TypeName 'System.Collections.ArrayList' - + Mock -CommandName 'Get-GroupMembersFromDirectoryEntry' -MockWith { } - + Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.DirectoryEntry' } -MockWith { return $ArgumentList[0] } - + Mock -CommandName 'Get-PrincipalContext' -MockWith { return $script:testPrincipalContext } Mock -CommandName 'Test-IsLocalMachine' -MockWith { return $true } - + Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.Security.Principal.SecurityIdentifier' } -MockWith { return 'S-1-0-0' } @@ -1714,7 +1719,7 @@ try It 'Should pass Credential to appropriate functions' { $getMembersResult = Get-MembersAsPrincipalsList -Group $script:testGroup -Credential $script:testCredential -PrincipalContextCache $principalContextCache -Disposables $disposables - + Assert-MockCalled -CommandName 'Get-PrincipalContext' -ParameterFilter { $Credential -eq $script:testCredential } Assert-MockCalled -CommandName 'Get-PrincipalContext' -ParameterFilter { $Credential -eq $script:testCredential} } @@ -1731,7 +1736,7 @@ try Context 'ConvertTo-UniquePrincipalsList' { $principalContextCache = @{} $disposables = New-Object -TypeName 'System.Collections.ArrayList' - + $testDomainUser1 = @{ Name = 'TestDomainUser1' SamAccountName = 'TestSamAccountName1' @@ -1751,11 +1756,11 @@ try $script:testUserPrincipal3.Name { return $script:testUserPrincipal3 } $testDomainUser1.Name { return $testDomainUser1 } } - } - + } + It 'Should not return duplicate local prinicpals' { $memberNames = @( $script:testUserPrincipal1.Name, $script:testUserPrincipal1.Name, $script:testUserPrincipal2.Name ) - + $uniquePrincipalsList = ConvertTo-UniquePrincipalsList -MemberNames $memberNames -PrincipalContextCache $principalContextCache -Disposables $disposables $uniquePrincipalsList | Should Be @( $script:testUserPrincipal1, $script:testUserPrincipal2 ) @@ -1787,7 +1792,7 @@ try Context 'ConvertTo-Principal' { $principalContextCache = @{} $disposables = New-Object -TypeName 'System.Collections.ArrayList' - + Mock -CommandName 'Split-MemberName' -MockWith { return $script:localDomain, $MemberName } Mock -CommandName 'Test-IsLocalMachine' -MockWith { return $true } Mock -CommandName 'Get-PrincipalContext' -MockWith { return $script:testPrincipalContext } @@ -1840,7 +1845,7 @@ try It 'Should throw if principal cannot be found' { $errorMessage = ($script:localizedData.CouldNotFindPrincipal -f $script:testUserPrincipal1.Name) - + { $convertToPrincipalResult = ConvertTo-Principal ` -MemberName $script:testUserPrincipal1.Name ` -PrincipalContextCache $principalContextCache ` @@ -1886,7 +1891,7 @@ try Context 'Get-PrincipalContext' { $fakePrincipalContext = 'FakePrincipalContext' - + Mock -CommandName 'Test-IsLocalMachine' -MockWith { return $true } Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.PrincipalContext' } -MockWith { $fakePrincipalContext } @@ -1912,12 +1917,12 @@ try It 'Should return the local principal context from the cache' { $principalContextCache = @{ $script:localDomain = $script:testPrincipalContext } $disposables = New-Object -TypeName 'System.Collections.ArrayList' - + Get-PrincipalContext -Scope $script:localDomain -PrincipalContextCache $principalContextCache -Disposables $disposables Assert-MockCalled -CommandName 'Test-IsLocalMachine' -ParameterFilter { $Scope -eq $script:localDomain } Assert-MockCalled -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.PrincipalContext' } -Times 0 -Scope 'It' - + $principalContextCache.$script:localDomain | Should Not Be $fakePrincipalContext $disposables.Contains($fakePrincipalContext) | Should Be $false } @@ -1929,7 +1934,7 @@ try $disposables = New-Object -TypeName 'System.Collections.ArrayList' $customDomain = 'CustomDomain' - + Get-PrincipalContext -Scope $customDomain -PrincipalContextCache $principalContextCache -Disposables $disposables Assert-MockCalled -CommandName 'Test-IsLocalMachine' -ParameterFilter { $Scope -eq $customDomain } @@ -1948,7 +1953,7 @@ try $disposables = New-Object -TypeName 'System.Collections.ArrayList' $customDomain = 'CustomDomain' - + Get-PrincipalContext -Scope $customDomain -Credential $script:testCredential -PrincipalContextCache $principalContextCache -Disposables $disposables Assert-MockCalled -CommandName 'Test-IsLocalMachine' -ParameterFilter { $Scope -eq $customDomain } @@ -1967,7 +1972,7 @@ try $disposables = New-Object -TypeName 'System.Collections.ArrayList' $customDomain = 'CustomDomain' - + $userNameWithDomain = 'CustomDomain\username' $testPassword = 'TestPassword' $secureTestPassword = ConvertTo-SecureString -String $testPassword -AsPlainText -Force @@ -1989,22 +1994,22 @@ try It 'Should return a custom principal context from the cache' { $customDomain = 'CustomDomain' - + $principalContextCache = @{ $customDomain = $script:testPrincipalContext } $disposables = New-Object -TypeName 'System.Collections.ArrayList' - + Get-PrincipalContext -Scope $customDomain -PrincipalContextCache $principalContextCache -Disposables $disposables Assert-MockCalled -CommandName 'Test-IsLocalMachine' -ParameterFilter { $Scope -eq $customDomain } Assert-MockCalled -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'System.DirectoryServices.AccountManagement.PrincipalContext' } -Times 0 -Scope 'It' - + $principalContextCache.$customDomain | Should Not Be $fakePrincipalContext $disposables.Contains($fakePrincipalContext) | Should Be $false } } } - + } } } diff --git a/Tests/Unit/MSFT_xMsiPackage.Tests.ps1 b/Tests/Unit/MSFT_xMsiPackage.Tests.ps1 index 28729fc10..d09d858d3 100644 --- a/Tests/Unit/MSFT_xMsiPackage.Tests.ps1 +++ b/Tests/Unit/MSFT_xMsiPackage.Tests.ps1 @@ -1,6 +1,15 @@ $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + Describe 'xMsiPackage Unit Tests' { BeforeAll { # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment diff --git a/Tests/Unit/MSFT_xPackageResource.Tests.ps1 b/Tests/Unit/MSFT_xPackageResource.Tests.ps1 index 665bf4e8b..55c4ed60e 100644 --- a/Tests/Unit/MSFT_xPackageResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xPackageResource.Tests.ps1 @@ -2,6 +2,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $script:testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $script:commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xPackageResource' ` diff --git a/Tests/Unit/MSFT_xRegistryResource.Tests.ps1 b/Tests/Unit/MSFT_xRegistryResource.Tests.ps1 index d8ea95eb7..26a8914b9 100644 --- a/Tests/Unit/MSFT_xRegistryResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xRegistryResource.Tests.ps1 @@ -6,6 +6,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xRegistryResource' ` @@ -18,7 +23,7 @@ try $script:validRegistryDriveRoots = @( 'HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE', 'HKEY_USERS', 'HKEY_CURRENT_CONFIG' ) $script:validRegistryDriveNames = @( 'HKCR', 'HKCU', 'HKLM', 'HKUS', 'HKCC' ) - + # This registry key is used ONLY for its type (Microsoft.Win32.RegistryKey). It is not actually accessed in any way during these tests. $script:testRegistryKey = [Microsoft.Win32.Registry]::CurrentConfig @@ -37,7 +42,7 @@ try Key = 'TestRegistryKey' ValueName = '' } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -97,7 +102,7 @@ try $getTargetResourceResult.ValueData | Should Be $null } } - + Mock -CommandName 'Get-RegistryKey' -MockWith { return $script:testRegistryKey } Context 'Specified registry key exists, registry key value name specified as an empty string, and registry key value data and type not specified' { @@ -105,7 +110,7 @@ try Key = 'TestRegistryKey' ValueName = '' } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -171,7 +176,7 @@ try Key = 'TestRegistryKey' ValueName = 'TestValueName' } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -254,7 +259,7 @@ try Key = 'TestRegistryKey' ValueName = 'TestValueName' } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -347,7 +352,7 @@ try ValueType = 'String' ValueData = 'TestValueData' } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -1016,7 +1021,7 @@ try Set-TargetResource @setTargetResourceParameters | Should Be $null } } - + Context 'Registry key exists, Ensure specified as Present, specified registry value does not exist, and registry value type and data not specified' { $setTargetResourceParameters = @{ Key = 'TestRegistryKey' @@ -1061,7 +1066,7 @@ try It 'Should convert the specified registry key value to a string' { $convertToStringParameterFilter = { - $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $script:defaultValueData -DifferenceObject $RegistryKeyValue) + $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $script:defaultValueData -DifferenceObject $RegistryKeyValue) return $registryKeyValueParameterCorrect } @@ -1181,7 +1186,7 @@ try It 'Should convert the specified registry key value to binary data' { $convertToBinaryParameterFilter = { - $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) + $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) return $registryKeyValueParameterCorrect } @@ -1311,7 +1316,7 @@ try It 'Should convert the specified registry key value to a multi-string' { $convertToMultiStringParameterFilter = { - $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) + $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) return $registryKeyValueParameterCorrect } @@ -1438,9 +1443,9 @@ try It 'Should convert the specified registry key value to a dword' { $convertToDwordParameterFilter = { - $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) + $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) $hexParameterCorrect = $Hex -eq $setTargetResourceParameters.Hex - + return $registryKeyValueParameterCorrect -and $hexParameterCorrect } @@ -1570,9 +1575,9 @@ try It 'Should convert the specified registry key value to a qword' { $convertToQwordParameterFilter = { - $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) + $registryKeyValueParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.ValueData -DifferenceObject $RegistryKeyValue) $hexParameterCorrect = $Hex -eq $setTargetResourceParameters.Hex - + return $registryKeyValueParameterCorrect -and $hexParameterCorrect } @@ -1846,7 +1851,7 @@ try } } } - + Describe 'xRegistry\Test-TargetResource' { Mock -CommandName 'Get-RegistryKeyValueDisplayName' -MockWith { return $RegistryKeyValueName } Mock -CommandName 'Test-RegistryKeyValuesMatch' -MockWith { return $true } @@ -2783,7 +2788,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'TestRegistryDriveName' } - + It 'Should throw error for unmountable registry drive' { $errorMessage = $script:localizedData.RegistryDriveCouldNotBeMounted -f $mountRegistryDriveParameters.RegistryDriveName @@ -2797,7 +2802,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'TestRegistryDriveName' } - + It 'Should throw error for unmountable registry drive' { $errorMessage = $script:localizedData.RegistryDriveCouldNotBeMounted -f $mountRegistryDriveParameters.RegistryDriveName @@ -2811,7 +2816,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'TestRegistryDriveName' } - + It 'Should throw error for unmountable registry drive' { $errorMessage = $script:localizedData.RegistryDriveCouldNotBeMounted -f $mountRegistryDriveParameters.RegistryDriveName @@ -2825,7 +2830,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'HKCR' } - + $expectedRegistryDriveRoot = 'HKEY_CLASSES_ROOT' It 'Should not throw' { @@ -2847,7 +2852,7 @@ try $rootParameterCorrect = $Root -eq $expectedRegistryDriveRoot $psProviderParameterCorrect = $PSProvider -eq 'Registry' $scopeParameterCorrect = $Scope -eq 'Script' - + return $nameParameterCorrect -and $rootParameterCorrect -and $psProviderParameterCorrect -and $scopeParameterCorrect } @@ -2865,7 +2870,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'TestRegistryDriveName' } - + It 'Should throw error for unmountable registry drive' { $errorMessage = $script:localizedData.RegistryDriveCouldNotBeMounted -f $mountRegistryDriveParameters.RegistryDriveName @@ -2879,7 +2884,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'TestRegistryDriveName' } - + It 'Should throw error for unmountable registry drive' { $errorMessage = $script:localizedData.RegistryDriveCouldNotBeMounted -f $mountRegistryDriveParameters.RegistryDriveName @@ -2893,7 +2898,7 @@ try $mountRegistryDriveParameters = @{ RegistryDriveName = 'HKCR' } - + $expectedRegistryDriveRoot = 'HKEY_CLASSES_ROOT' It 'Should not throw' { @@ -3223,7 +3228,7 @@ try $convertToReadableStringResult | Should Be ([String]::Empty) } } - + Context "Registry key value specified as an empty array and registry key type specified as $registryKeyValueType" { $convertToReadableStringParameters = @{ RegistryKeyValue = @() diff --git a/Tests/Unit/MSFT_xRemoteFile.Tests.ps1 b/Tests/Unit/MSFT_xRemoteFile.Tests.ps1 index 1ae20fe59..86c0e75e4 100644 --- a/Tests/Unit/MSFT_xRemoteFile.Tests.ps1 +++ b/Tests/Unit/MSFT_xRemoteFile.Tests.ps1 @@ -1,6 +1,15 @@ +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $commonTestHelperFilePath + $Global:DSCModuleName = 'xPSDesiredStateConfiguration' $Global:DSCResourceName = 'MSFT_xRemoteFile' +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + #region HEADER # Unit Test Template Version: 1.1.0 [String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) @@ -14,7 +23,7 @@ Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHel $TestEnvironment = Initialize-TestEnvironment ` -DSCModuleName $Global:DSCModuleName ` -DSCResourceName $Global:DSCResourceName ` - -TestType Unit + -TestType Unit #endregion HEADER # Create a working folder that all files will be created in @@ -39,11 +48,11 @@ try [System.String] $errorMessage ) - + $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidData $exception = New-Object ` -TypeName System.InvalidOperationException ` - -ArgumentList $errorMessage + -ArgumentList $errorMessage $errorRecord = New-Object ` -TypeName System.Management.Automation.ErrorRecord ` -ArgumentList $exception, $errorId, $errorCategory, $null diff --git a/Tests/Unit/MSFT_xScriptResource.Tests.ps1 b/Tests/Unit/MSFT_xScriptResource.Tests.ps1 index 7e45dbe43..dfd2f275e 100644 --- a/Tests/Unit/MSFT_xScriptResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xScriptResource.Tests.ps1 @@ -6,6 +6,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DSCResourceModuleName 'xPSDesiredStateConfiguration' ` -DSCResourceName 'MSFT_xScriptResource' ` @@ -77,7 +82,7 @@ try { TestScript = 'NotUsed' SetScript = 'NotUsed' } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -94,7 +99,7 @@ try { Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter $invokeScriptParameterFilter -Times 1 -Scope 'It' } - + It 'Should return a hashtable' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters $getTargetResourceResult -is [Hashtable] | Should Be $true @@ -113,7 +118,7 @@ try { SetScript = 'NotUsed' Credential = $script:testCredenital } - + It 'Should not throw' { { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw } @@ -126,13 +131,13 @@ try { $invokeScriptParameterFilter = { $scriptBlockParameterCorrect = $null -eq (Compare-Object -ReferenceObject $expectedScriptBlock.Ast -DifferenceObject $ScriptBlock.Ast) $credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $getTargetResourceParameters.Credential -DifferenceObject $Credential) - - return $scriptBlockParameterCorrect -and $credentialParameterCorrect + + return $scriptBlockParameterCorrect -and $credentialParameterCorrect } Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter $invokeScriptParameterFilter -Times 1 -Scope 'It' } - + It 'Should return a hashtable' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters $getTargetResourceResult -is [Hashtable] | Should Be $true @@ -193,8 +198,8 @@ try { $invokeScriptParameterFilter = { $scriptBlockParameterCorrect = $null -eq (Compare-Object -ReferenceObject $expectedScriptBlock.Ast -DifferenceObject $ScriptBlock.Ast) $credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $setTargetResourceParameters.Credential -DifferenceObject $Credential) - - return $scriptBlockParameterCorrect -and $credentialParameterCorrect + + return $scriptBlockParameterCorrect -and $credentialParameterCorrect } Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter $invokeScriptParameterFilter -Times 1 -Scope 'It' @@ -280,7 +285,7 @@ try { Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter $invokeScriptParameterFilter -Times 1 -Scope 'It' } - + It 'Should return the expected boolean' { $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters $testTargetResourceResult | Should Be $expectedBoolean @@ -307,13 +312,13 @@ try { $invokeScriptParameterFilter = { $scriptBlockParameterCorrect = $null -eq (Compare-Object -ReferenceObject $expectedScriptBlock.Ast -DifferenceObject $ScriptBlock.Ast) $credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $testTargetResourceParameters.Credential -DifferenceObject $Credential) - - return $scriptBlockParameterCorrect -and $credentialParameterCorrect + + return $scriptBlockParameterCorrect -and $credentialParameterCorrect } Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter $invokeScriptParameterFilter -Times 1 -Scope 'It' } - + It 'Should return the expected boolean' { $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters $testTargetResourceResult | Should Be $expectedBoolean @@ -346,7 +351,7 @@ try { Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter $invokeScriptParameterFilter -Times 1 -Scope 'It' } - + It 'Should return the expected boolean' { $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters $testTargetResourceResult | Should Be $expectedBoolean @@ -443,7 +448,7 @@ try { It 'Should return result of script' { $scriptExecutionHelperResult = Invoke-Script @scriptExecutionHelperParameters $scriptExecutionHelperResult | Should Be $testScriptResult - } + } } } } diff --git a/Tests/Unit/MSFT_xServiceResource.Tests.ps1 b/Tests/Unit/MSFT_xServiceResource.Tests.ps1 index ec95c9f68..f61793731 100644 --- a/Tests/Unit/MSFT_xServiceResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xServiceResource.Tests.ps1 @@ -10,6 +10,11 @@ $script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent $script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1' Import-Module -Name $commonTestHelperFilePath +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DSCResourceModuleName 'xPSDesiredStateConfiguration' ` -DSCResourceName 'MSFT_xServiceResource' ` diff --git a/Tests/Unit/MSFT_xUserResource.Tests.ps1 b/Tests/Unit/MSFT_xUserResource.Tests.ps1 index 8e2c0f2a9..01dee4f3b 100644 --- a/Tests/Unit/MSFT_xUserResource.Tests.ps1 +++ b/Tests/Unit/MSFT_xUserResource.Tests.ps1 @@ -6,6 +6,11 @@ Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` -ChildPath 'CommonTestHelper.psm1') ` -Force +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DSCResourceModuleName 'xPSDesiredStateConfiguration' ` -DSCResourceName 'MSFT_xUserResource' ` @@ -21,31 +26,31 @@ try { InModuleScope 'MSFT_xUserResource' { # Used to skip the Nano server tests for the time being since they are not working on AppVeyor - + $script:skipMe = $true - + $existingUserName = 'TestUserName12345' $existingUserPassword = 'StrongOne7.' $existingDescription = 'Some Description' $existingSecurePassword = ConvertTo-SecureString $existingUserPassword -AsPlainText -Force $existingTestCredential = New-Object PSCredential ($existingUserName, $existingSecurePassword) - + New-User -Credential $existingTestCredential -Description $existingDescription - + $newUserName1 = 'NewTestUserName12345' $newUserPassword1 = 'NewStrongOne123.' $newFullName1 = 'Fullname1' $newUserDescription1 = 'New Description1' $newSecurePassword1 = ConvertTo-SecureString $newUserPassword1 -AsPlainText -Force $newCredential1 = New-Object PSCredential ($newUserName1, $newSecurePassword1) - + $newUserName2 = 'newUser1234' $newPassword2 = 'ThisIsAStrongPassword543!' $newFullName2 = 'Fullname2' $newUserDescription2 = 'New Description2' $newSecurePassword2 = ConvertTo-SecureString $newPassword2 -AsPlainText -Force $newCredential2 = New-Object PSCredential ($newUserName2, $newSecurePassword2) - + try { Describe 'xUserResource/Get-TargetResource' { @@ -94,28 +99,28 @@ try { Describe 'xUserResource/Set-TargetResource' { Context 'Tests on FullSKU' { Mock -CommandName Test-IsNanoServer -MockWith { return $false } - + try { New-User -Credential $newCredential1 -Description $newUserDescription1 - + It 'Should remove the user' { Test-User -UserName $newUserName1 | Should Be $true Set-TargetResource -UserName $newUserName1 -Ensure 'Absent' Test-User -UserName $newUserName1 | Should Be $false } - + It 'Should add the new user' { Set-TargetResource -UserName $newUserName2 -Password $newCredential2 -Ensure 'Present' Test-User -UserName $newUserName2 | Should Be $true } - + It 'Should update the user' { $disabled = $false $passwordNeverExpires = $true $passwordChangeRequired = $false $passwordChangeNotAllowed = $true - + Set-TargetResource -UserName $newUserName2 ` -Password $newCredential2 ` -Ensure 'Present' ` @@ -125,9 +130,9 @@ try { -PasswordNeverExpires $passwordNeverExpires ` -PasswordChangeRequired $passwordChangeRequired ` -PasswordChangeNotAllowed $passwordChangeNotAllowed - + Test-User -UserName $newUserName2 | Should Be $true - $testTargetResourceResult1 = + $testTargetResourceResult1 = Test-TargetResource -UserName $newUserName2 ` -Password $newCredential2 ` -Ensure 'Present' ` @@ -143,7 +148,7 @@ try { $passwordNeverExpires = $false $passwordChangeRequired = $true $passwordChangeNotAllowed = $false - + Set-TargetResource -UserName $newUserName2 ` -Password $newCredential1 ` -Ensure 'Present' ` @@ -153,9 +158,9 @@ try { -PasswordNeverExpires $passwordNeverExpires ` -PasswordChangeRequired $passwordChangeRequired ` -PasswordChangeNotAllowed $passwordChangeNotAllowed - + Test-User -UserName $newUserName2 | Should Be $true - $testTargetResourceResult2 = + $testTargetResourceResult2 = Test-TargetResource -UserName $newUserName2 ` -Password $newCredential1 ` -Ensure 'Present' ` @@ -177,28 +182,28 @@ try { Context 'Tests on Nano Server' { Mock -CommandName Test-IsNanoServer -MockWith { return $true } Mock -CommandName Test-CredentialsValidOnNanoServer { return $true } - + try { New-User -Credential $newCredential1 -Description $newUserDescription1 - + It 'Should remove the user' -Skip:$script:skipMe { Test-User -UserName $newUserName1 | Should Be $true Set-TargetResource -UserName $newUserName1 -Ensure 'Absent' Test-User -UserName $newUserName1 | Should Be $false } - + It 'Should add the new user' -Skip:$script:skipMe { Set-TargetResource -UserName $newUserName2 -Password $newCredential2 -Ensure 'Present' Test-User -UserName $newUserName2 | Should Be $true } - + It 'Should update the user' -Skip:$script:skipMe { $disabled = $false $passwordNeverExpires = $true $passwordChangeRequired = $false $passwordChangeNotAllowed = $true - + Set-TargetResource -UserName $newUserName2 ` -Password $newCredential2 ` -Ensure 'Present' ` @@ -208,9 +213,9 @@ try { -PasswordNeverExpires $passwordNeverExpires ` -PasswordChangeRequired $passwordChangeRequired ` -PasswordChangeNotAllowed $passwordChangeNotAllowed - + Test-User -UserName $newUserName2 | Should Be $true - $testTargetResourceResult1 = + $testTargetResourceResult1 = Test-TargetResource -UserName $newUserName2 ` -Password $newCredential2 ` -Ensure 'Present' ` @@ -226,7 +231,7 @@ try { $passwordNeverExpires = $false $passwordChangeRequired = $true $passwordChangeNotAllowed = $false - + Set-TargetResource -UserName $newUserName2 ` -Password $newCredential1 ` -Ensure 'Present' ` @@ -236,9 +241,9 @@ try { -PasswordNeverExpires $passwordNeverExpires ` -PasswordChangeRequired $passwordChangeRequired ` -PasswordChangeNotAllowed $passwordChangeNotAllowed - + Test-User -UserName $newUserName2 | Should Be $true - $testTargetResourceResult2 = + $testTargetResourceResult2 = Test-TargetResource -UserName $newUserName2 ` -Password $newCredential1 ` -Ensure 'Present' ` @@ -262,7 +267,7 @@ try { Context 'Tests on FullSKU' { Mock -CommandName Test-IsNanoServer -MockWith { return $false } $absentUserName = 'AbsentUserUserName123456789' - + It 'Should return true when user Present and correct values' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Description $existingDescription ` @@ -272,7 +277,7 @@ try { -PasswordChangeNotAllowed $false $testTargetResourceResult | Should Be $true } - + It 'Should return true when user Absent and Ensure = Absent' { $testTargetResourceResult = Test-TargetResource -UserName $absentUserName ` -Ensure 'Absent' @@ -284,23 +289,23 @@ try { -Ensure 'Present' $testTargetResourceResult | Should Be $false } - + It 'Should return false when user Present and Ensure = Absent' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Ensure 'Absent' $testTargetResourceResult | Should Be $false } - + It 'Should return false when Password is wrong' { $badPassword = 'WrongPassword' $secureBadPassword = ConvertTo-SecureString $badPassword -AsPlainText -Force $badTestCredential = New-Object PSCredential ($existingUserName, $secureBadPassword) - + $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Password $badTestCredential $testTargetResourceResult | Should Be $false } - + It 'Should return false when user Present and wrong Description' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Description 'Wrong description' @@ -310,36 +315,36 @@ try { It 'Should return false when FullName is incorrect' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -FullName 'Wrong FullName' - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } - + It 'Should return false when Disabled is incorrect' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Disabled $true - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } - + It 'Should return false when PasswordNeverExpires is incorrect' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -PasswordNeverExpires $true - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } - + It 'Should return false when PasswordChangeNotAllowed is incorrect' { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -PasswordChangeNotAllowed $true - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } } - + Context 'Tests on Nano Server' { Mock -CommandName Test-IsNanoServer -MockWith { return $true } - + $absentUserName = 'AbsentUserUserName123456789' - + It 'Should return true when user Present and correct values' -Skip:$script:skipMe { Mock -CommandName Test-CredentialsValidOnNanoServer { return $true } - + $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Description $existingDescription ` -Password $existingTestCredential ` @@ -348,7 +353,7 @@ try { -PasswordChangeNotAllowed $false $testTargetResourceResult | Should Be $true } - + It 'Should return true when user Absent and Ensure = Absent' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $absentUserName ` -Ensure 'Absent' @@ -360,25 +365,25 @@ try { -Ensure 'Present' $testTargetResourceResult | Should Be $false } - + It 'Should return false when user Present and Ensure = Absent' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Ensure 'Absent' $testTargetResourceResult | Should Be $false } - + It 'Should return false when Password is wrong' -Skip:$script:skipMe { Mock -CommandName Test-CredentialsValidOnNanoServer { return $false } - + $badPassword = 'WrongPassword' $secureBadPassword = ConvertTo-SecureString $badPassword -AsPlainText -Force $badTestCredential = New-Object PSCredential ($existingUserName, $secureBadPassword) - + $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Password $badTestCredential $testTargetResourceResult | Should Be $false } - + It 'Should return false when user Present and wrong Description' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Description 'Wrong description' @@ -388,34 +393,34 @@ try { It 'Should return false when FullName is incorrect' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -FullName 'Wrong FullName' - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } - + It 'Should return false when Disabled is incorrect' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -Disabled $true - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } - + It 'Should return false when PasswordNeverExpires is incorrect' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -PasswordNeverExpires $true - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } - + It 'Should return false when PasswordChangeNotAllowed is incorrect' -Skip:$script:skipMe { $testTargetResourceResult = Test-TargetResource -UserName $existingUserName ` -PasswordChangeNotAllowed $true - $testTargetResourceResult | Should Be $false + $testTargetResourceResult | Should Be $false } } } - + Describe 'xUserResource/Assert-UserNameValid' { It 'Should not throw when username contains all valid chars' { { Assert-UserNameValid -UserName 'abc123456!f_t-l098s' } | Should Not Throw } - + It 'Should throw InvalidArgumentError when username contains only whitespace and dots' { $invalidName = ' . .. . ' $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument @@ -425,7 +430,7 @@ try { $errorRecord = New-Object System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $null { Assert-UserNameValid -UserName $invalidName } | Should Throw $errorRecord } - + It 'Should throw InvalidArgumentError when username contains an invalid char' { $invalidName = 'user|name' $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument diff --git a/Tests/Unit/MSFT_xWindowsFeature.Tests.ps1 b/Tests/Unit/MSFT_xWindowsFeature.Tests.ps1 index defbc825a..80fbcce05 100644 --- a/Tests/Unit/MSFT_xWindowsFeature.Tests.ps1 +++ b/Tests/Unit/MSFT_xWindowsFeature.Tests.ps1 @@ -6,6 +6,11 @@ Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` -ChildPath 'CommonTestHelper.psm1') ` -Force +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DSCResourceModuleName 'xPSDesiredStateConfiguration' ` -DSCResourceName 'MSFT_xWindowsFeature' ` @@ -27,12 +32,12 @@ try { $mockWindowsFeatures = @{ - Test1 = @{ + Test1 = @{ Name = 'Test1' DisplayName = 'Test Feature 1' Description = 'Test Feature with 3 subfeatures' - Installed = $false - InstallState = 'Available' + Installed = $false + InstallState = 'Available' FeatureType = 'Role Service' Path = 'Test1' Depth = 1 @@ -48,7 +53,7 @@ try { AdditionalInfo = @('MajorVersion', 'MinorVersion', 'NumericId', 'InstallName') } - SubTest1 = @{ + SubTest1 = @{ Name = 'SubTest1' DisplayName = 'Sub Test Feature 1' Description = 'Sub Test Feature with parent as test1' @@ -69,7 +74,7 @@ try { AdditionalInfo = @('MajorVersion', 'MinorVersion', 'NumericId', 'InstallName') } - SubTest2 = @{ + SubTest2 = @{ Name = 'SubTest2' DisplayName = 'Sub Test Feature 2' Description = 'Sub Test Feature with parent as test1' @@ -111,12 +116,12 @@ try { AdditionalInfo = @('MajorVersion', 'MinorVersion', 'NumericId', 'InstallName') } - Test2 = @{ + Test2 = @{ Name = 'Test2' DisplayName = 'Test Feature 2' Description = 'Test Feature with 0 subfeatures' - Installed = $true - InstallState = 'Available' + Installed = $true + InstallState = 'Available' FeatureType = 'Role Service' Path = 'Test2' Depth = 1 @@ -141,7 +146,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testWindowsFeatureName2] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -149,7 +154,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testWindowsFeatureName1] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -157,7 +162,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testSubFeatureName1] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -165,7 +170,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testSubFeatureName2] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -173,13 +178,13 @@ try { $windowsFeature = $mockWindowsFeatures[$testSubFeatureName3] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } - + Context 'Windows Feature exists with no sub features' { - + It 'Should return the correct hashtable when not on a 2008 Server' { Mock -CommandName Test-IsWinServer2008R2SP1 -MockWith { return $false } @@ -202,11 +207,11 @@ try { It 'Should return the correct hashtable when on a 2008 Server and Credential is passed' { Mock -CommandName Test-IsWinServer2008R2SP1 -MockWith { return $true } - Mock -CommandName Invoke-Command -MockWith { + Mock -CommandName Invoke-Command -MockWith { $windowsFeature = $mockWindowsFeatures[$testWindowsFeatureName2] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -259,7 +264,7 @@ try { } } } - + Describe 'xWindowsFeature/Set-TargetResource' { Mock -CommandName Import-ServerManager -MockWith {} @@ -275,7 +280,7 @@ try { } $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -288,7 +293,7 @@ try { } $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -316,7 +321,7 @@ try { } $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -329,18 +334,18 @@ try { } $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } It 'Should throw invalid operation exception when Ensure set to Present' { - { Set-TargetResource -Name $testWindowsFeatureName2 -Ensure 'Present' } | + { Set-TargetResource -Name $testWindowsFeatureName2 -Ensure 'Present' } | Should Throw ($script:localizedData.FeatureInstallationFailureError -f $testWindowsFeatureName2) Assert-MockCalled -CommandName Add-WindowsFeature -Times 1 -Exactly -Scope It } It 'Should throw invalid operation exception when Ensure set to Absent' { - { Set-TargetResource -Name $testWindowsFeatureName2 -Ensure 'Absent' } | + { Set-TargetResource -Name $testWindowsFeatureName2 -Ensure 'Absent' } | Should Throw ($script:localizedData.FeatureUninstallationFailureError -f $testWindowsFeatureName2) Assert-MockCalled -CommandName Remove-WindowsFeature -Times 1 -Exactly -Scope It } @@ -359,7 +364,7 @@ try { } $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -368,7 +373,7 @@ try { It 'Should install the feature when Ensure set to Present and Credential passed in' { - { + { Set-TargetResource -Name $testWindowsFeatureName2 ` -Ensure 'Present' ` -Credential $testCredential @@ -379,7 +384,7 @@ try { It 'Should uninstall the feature when Ensure set to Absent and Credential passed in' { - { + { Set-TargetResource -Name $testWindowsFeatureName2 ` -Ensure 'Absent' ` -Credential $testCredential @@ -397,7 +402,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testWindowsFeatureName1] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -405,7 +410,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testSubFeatureName1] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -413,7 +418,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testSubFeatureName2] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -421,7 +426,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testSubFeatureName3] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -430,7 +435,7 @@ try { $windowsFeature = $mockWindowsFeatures[$testWindowsFeatureName1] $windowsFeatureObject = New-Object -TypeName PSObject -Property $windowsFeature $windowsFeatureObject.PSTypeNames[0] = 'Microsoft.Windows.ServerManager.Commands.Feature' - + return $windowsFeatureObject } @@ -562,12 +567,12 @@ try { It 'Should throw invalid operation when feature equals null' { $nonexistentName = 'NonexistentFeatureName' - { Assert-SingleFeatureExists -Feature $null -Name $nonexistentName } | + { Assert-SingleFeatureExists -Feature $null -Name $nonexistentName } | Should Throw ($script:localizedData.FeatureNotFoundError -f $nonexistentName) } It 'Should throw invalid operation when there are multiple features with the given name' { - { Assert-SingleFeatureExists -Feature $multipleFeature -Name $multipleFeature.Name } | + { Assert-SingleFeatureExists -Feature $multipleFeature -Name $multipleFeature.Name } | Should Throw ($script:localizedData.MultipleFeatureInstancesError -f $multipleFeature.Name) } } @@ -584,14 +589,14 @@ try { Mock -CommandName Import-Module -MockWith {} { Import-ServerManager } | Should Not Throw } - + It 'Should Not Throw when exception is Identity Reference Runtime Exception' { $mockIdentityReferenceRuntimeException = New-Object -TypeName System.Management.Automation.RuntimeException -ArgumentList 'Some or all identity references could not be translated' Mock -CommandName Import-Module -MockWith { Throw $mockIdentityReferenceRuntimeException } { Import-ServerManager } | Should Not Throw } - + It 'Should throw invalid operation exception when exception is not Identity Reference Runtime Exception' { $mockOtherRuntimeException = New-Object -TypeName System.Management.Automation.RuntimeException -ArgumentList 'Other error' Mock -CommandName Import-Module -MockWith { Throw $mockOtherRuntimeException } diff --git a/Tests/Unit/MSFT_xWindowsOptionalFeature.Tests.ps1 b/Tests/Unit/MSFT_xWindowsOptionalFeature.Tests.ps1 index 995801664..e811361e9 100644 --- a/Tests/Unit/MSFT_xWindowsOptionalFeature.Tests.ps1 +++ b/Tests/Unit/MSFT_xWindowsOptionalFeature.Tests.ps1 @@ -1,5 +1,10 @@ Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'CommonTestHelper.psm1') +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsOptionalFeature' ` @@ -14,7 +19,7 @@ try $script:testFeatureName = 'TestFeature' - $script:fakeEnabledFeature = [PSCustomObject] @{ + $script:fakeEnabledFeature = [PSCustomObject] @{ Name = $testFeatureName State = 'Enabled' } @@ -27,7 +32,7 @@ try <# This context block needs to stay at the top because of a bug in Pester on Nano server. - + Assert-ResourcePrerequisitesValid is mocked in most of the other contexts blocks. This causes errors to throw from the script blocks in this context since this function does not take any parameters, but Pester tries to pipe something into it. @@ -57,7 +62,7 @@ try BuildNumber = 9600 } } - + It 'Should throw when the DISM module is not available' { Mock Import-Module -ParameterFilter { $Name -eq 'Dism' } -MockWith { Write-Error 'Cannot find module' } { Assert-ResourcePrerequisitesValid } | Should Throw $script:localizedData.DismNotAvailable @@ -111,7 +116,7 @@ try } } - + Context 'Get-TargetResource - Feature Disabled' { Mock Assert-ResourcePrerequisitesValid -MockWith { } Mock Dism\Get-WindowsOptionalFeature { $FeatureName -eq $script:testFeatureName } -MockWith { return $script:fakeDisabledFeature } @@ -167,9 +172,9 @@ try It 'Should call Enable-WindowsOptionalFeature with NoRestart set to true by default when Ensure set to Present' { Mock Dism\Enable-WindowsOptionalFeature -ParameterFilter { $NoRestart -eq $true } -MockWith { } - + Set-TargetResource -Name $script:testFeatureName - + Assert-MockCalled Dism\Enable-WindowsOptionalFeature -ParameterFilter { $NoRestart -eq $true } -Scope It } @@ -306,7 +311,7 @@ try It 'Should return the correct string for each object' { $propertiesAsStrings = Convert-CustomPropertyArrayToStringArray -CustomProperties $psCustomObjects - + foreach ($objectNumber in @(1, 2, 3)) { $propertiesAsStrings.Contains("Name = Object $objectNumber, Value = Value $objectNumber, Path = Path $objectNumber") | Should Be $true diff --git a/Tests/Unit/MSFT_xWindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_xWindowsPackageCab.Tests.ps1 index 1284b7d39..06109baa6 100644 --- a/Tests/Unit/MSFT_xWindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_xWindowsPackageCab.Tests.ps1 @@ -1,5 +1,10 @@ Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'CommonTestHelper.psm1') +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsPackageCab' ` diff --git a/Tests/Unit/MSFT_xWindowsProcess.Tests.ps1 b/Tests/Unit/MSFT_xWindowsProcess.Tests.ps1 index abd19f8b8..cdc6f1e70 100644 --- a/Tests/Unit/MSFT_xWindowsProcess.Tests.ps1 +++ b/Tests/Unit/MSFT_xWindowsProcess.Tests.ps1 @@ -7,6 +7,11 @@ Set-StrictMode -Version 'Latest' Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` -ChildPath 'CommonTestHelper.psm1') +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceModuleName 'xPSDesiredStateConfiguration' ` -DscResourceName 'MSFT_xWindowsProcess' ` @@ -89,10 +94,10 @@ try Describe 'xWindowsProcess\Get-TargetResource' { Mock -CommandName Expand-Path -MockWith { return $Path } - Mock -CommandName Get-ProcessCimInstance -MockWith { + Mock -CommandName Get-ProcessCimInstance -MockWith { if ($Path -eq $script:validPath1) { - return @($script:mockProcess1, $script:mockProcess3) + return @($script:mockProcess1, $script:mockProcess3) } elseif ($Path -eq $script:validPath2) { @@ -110,7 +115,7 @@ try Mock -CommandName Get-Process -MockWith { if ($ID -eq $script:mockProcess1.Id) { - return $script:mockProcess1 + return $script:mockProcess1 } elseif ($script:mockProcess2.Id) { @@ -127,27 +132,27 @@ try } Mock -CommandName New-InvalidOperationException -MockWith { Throw $script:exceptionMessage } Mock -CommandName New-InvalidArgumentException -MockWith { Throw $script:exceptionMessage } - + It 'Should return the correct properties for a process that is Absent' { $processArguments = 'TestGetProperties' - + $getTargetResourceResult = Get-TargetResource -Path $invalidPath ` -Arguments $processArguments - + $getTargetResourceResult.Arguments | Should Be $processArguments $getTargetResourceResult.Ensure | Should Be 'Absent' $getTargetResourceResult.Path | Should Be $invalidPath - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It } - + It 'Should return the correct properties for one process with a credential' { - + $getTargetResourceResult = Get-TargetResource -Path $script:validPath2 ` -Arguments $script:mockProcess2.Arguments ` -Credential $script:testCredential - + $getTargetResourceResult.VirtualMemorySize | Should Be $script:mockProcess2.VirtualMemorySize64 $getTargetResourceResult.Arguments | Should Be $script:mockProcess2.Arguments $getTargetResourceResult.Ensure | Should Be 'Present' @@ -156,17 +161,17 @@ try $getTargetResourceResult.NonPagedMemorySize | Should Be $script:mockProcess2.NonpagedSystemMemorySize64 $getTargetResourceResult.HandleCount | Should Be $script:mockProcess2.HandleCount $getTargetResourceResult.ProcessId | Should Be $script:mockProcess2.ProcessId - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It } - + It 'Should return the correct properties when there are multiple processes' { - + $getTargetResourceResult = Get-TargetResource -Path $script:validPath1 ` -Arguments $script:mockProcess1.Arguments - + $getTargetResourceResult.VirtualMemorySize | Should Be $script:mockProcess1.VirtualMemorySize64 $getTargetResourceResult.Arguments | Should Be $script:mockProcess1.Arguments $getTargetResourceResult.Ensure | Should Be 'Present' @@ -175,19 +180,19 @@ try $getTargetResourceResult.NonPagedMemorySize | Should Be $script:mockProcess1.NonpagedSystemMemorySize64 $getTargetResourceResult.HandleCount | Should Be $script:mockProcess1.HandleCount $getTargetResourceResult.ProcessId | Should Be $script:mockProcess1.ProcessId - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It } } - + Describe 'xWindowsProcess\Set-TargetResource' { Mock -CommandName Expand-Path -MockWith { return $Path } - Mock -CommandName Get-ProcessCimInstance -MockWith { + Mock -CommandName Get-ProcessCimInstance -MockWith { if ($Path -eq $script:validPath1) { - return @($script:mockProcess1, $script:mockProcess3) + return @($script:mockProcess1, $script:mockProcess3) } elseif ($Path -eq $script:validPath2) { @@ -219,38 +224,38 @@ try -Credential $script:testCredential ` -Ensure 'Absent' } | Should Not Throw - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Stop-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 1 -Scope It } - + It 'Should not throw when Ensure set to Absent and processes are not running' { { Set-TargetResource -Path $script:invalidPath ` -Arguments '' ` -Ensure 'Absent' } | Should Not Throw - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Stop-Process -Exactly 0 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 0 -Scope It } - + It 'Should throw an invalid operation exception when Stop-Process throws an error' { { Set-TargetResource -Path $script:errorProcess.Path ` -Arguments '' ` -Ensure 'Absent' } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Stop-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName New-InvalidOperationException -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 0 -Scope It } - + Mock -CommandName Wait-ProcessCount -MockWith { return $false } It 'Should throw an invalid operation exception when there is a problem waiting for the processes' { @@ -258,14 +263,14 @@ try -Arguments $script:mockProcess1.Arguments ` -Ensure 'Absent' } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Stop-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 1 -Scope It Assert-MockCalled -CommandName New-InvalidOperationException -Exactly 1 -Scope It } - + Mock -CommandName Wait-ProcessCount -MockWith { return $true } Mock -CommandName Start-ProcessAsLocalSystemUser -MockWith {} @@ -275,14 +280,14 @@ try -Credential $script:testCredential ` -Ensure 'Present' } | Should Not Throw - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Test-IsRunFromLocalSystemUser -Exactly 1 -Scope It Assert-MockCalled -CommandName Start-ProcessAsLocalSystemUser -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 1 -Scope It } - + Mock -CommandName Start-ProcessAsLocalSystemUser -MockWith {} Mock -CommandName Assert-PathArgumentRooted -MockWith {} Mock -CommandName Assert-PathArgumentValid -MockWith {} @@ -294,7 +299,7 @@ try -WorkingDirectory 'test working directory' ` -Ensure 'Present' } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Test-IsRunFromLocalSystemUser -Exactly 1 -Scope It @@ -304,7 +309,7 @@ try Assert-MockCalled -CommandName Assert-PathArgumentValid -Exactly 1 -Scope It Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } - + $testErrorRecord = 'test Start-ProcessAsLocalSystemUser error record' Mock -CommandName Start-ProcessAsLocalSystemUser -MockWith { Throw $testErrorRecord } @@ -314,14 +319,14 @@ try -Credential $script:testCredential ` -Ensure 'Present' } | Should Throw $testErrorRecord - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Test-IsRunFromLocalSystemUser -Exactly 1 -Scope It Assert-MockCalled -CommandName Start-ProcessAsLocalSystemUser -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 0 -Scope It } - + Mock -CommandName Start-Process -MockWith {} It 'Should not throw when Ensure set to Present and processes are not running and no credential passed' { @@ -329,13 +334,13 @@ try -Arguments $script:mockProcess1.Arguments ` -Ensure 'Present' } | Should Not Throw - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Start-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 1 -Scope It } - + $mockStartProcessException = New-Object -TypeName 'InvalidOperationException' ` -ArgumentList @('Start-Process test exception') Mock -CommandName Start-Process -MockWith { Throw $mockStartProcessException } @@ -345,14 +350,14 @@ try -Arguments $script:mockProcess1.Arguments ` -Ensure 'Present' } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Start-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 0 -Scope It Assert-MockCalled -CommandName New-InvalidOperationException -Exactly 1 -Scope It } - + Mock -CommandName Wait-ProcessCount -MockWith { return $false } Mock -CommandName Start-Process -MockWith {} @@ -361,13 +366,13 @@ try -Arguments $script:mockProcess1.Arguments ` -Ensure 'Present' } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Start-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 1 -Scope It } - + Mock -CommandName Wait-ProcessCount -MockWith { return $true } It 'Should not throw when Ensure set to Present and processes are already running' { @@ -375,20 +380,20 @@ try -Arguments $script:mockProcess1.Arguments ` -Ensure 'Present' } | Should Not Throw - + Assert-MockCalled -CommandName Expand-Path -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessCimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Start-Process -Exactly 0 -Scope It Assert-MockCalled -CommandName Wait-ProcessCount -Exactly 0 -Scope It } } - + Describe 'xWindowsProcess\Test-TargetResource' { Mock -CommandName Expand-Path -MockWith { return $Path } - Mock -CommandName Get-ProcessCimInstance -MockWith { + Mock -CommandName Get-ProcessCimInstance -MockWith { if ($Path -eq $script:validPath1) { - return @($script:mockProcess1, $script:mockProcess3) + return @($script:mockProcess1, $script:mockProcess3) } elseif ($Path -eq $script:validPath2) { @@ -410,14 +415,14 @@ try -Ensure 'Present' $testTargetResourceResult | Should Be $true } - + It 'Should return false when Ensure set to Present and process is not running' { $testTargetResourceResult = Test-TargetResource -Path $script:invalidPath ` -Arguments $script:mockProcess1.Arguments ` -Ensure 'Present' $testTargetResourceResult | Should Be $false } - + It 'Should return true when Ensure set to Absent and process is not running and Credential passed' { $testTargetResourceResult = Test-TargetResource -Path $script:invalidPath ` -Arguments $script:mockProcess1.Arguments ` @@ -425,46 +430,46 @@ try -Ensure 'Absent' $testTargetResourceResult | Should Be $true } - + It 'Should return false when Ensure set to Absent and process is running' { $testTargetResourceResult = Test-TargetResource -Path $script:validPath1 ` -Arguments $script:mockProcess1.Arguments ` -Ensure 'Absent' $testTargetResourceResult | Should Be $false } - + } - + Describe 'xWindowsProcess\Expand-Path' { Mock -CommandName New-InvalidArgumentException -MockWith { Throw $script:exceptionMessage } Mock -CommandName Test-Path -MockWith { return $true } It 'Should return the original path when path is rooted' { $rootedPath = 'C:\testProcess.exe' - + $expandPathResult = Expand-Path -Path $rootedPath $expandPathResult | Should Be $rootedPath } - + Mock -CommandName Test-Path -MockWith { return $false } It 'Should throw an invalid argument exception when Path is rooted and does not exist' { $rootedPath = 'C:\invalidProcess.exe' - + { Expand-Path -Path $rootedPath} | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } - + It 'Should throw an invalid argument exception when Path is unrooted and does not exist' { $unrootedPath = 'invalidfile.txt' - + { Expand-Path -Path $unrootedPath} | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } } - + Describe 'xWindowsProcess\Get-ProcessCimInstance' { Mock -CommandName Get-Process -MockWith { return @($script:mockProcess2) } Mock -CommandName Get-CimInstance -MockWith { return $script:mockProcess2 } @@ -472,11 +477,11 @@ try It 'Should return the correct process when it exists and no arguments passed' { $resultProcess = Get-ProcessCimInstance -Path $script:mockProcess2.Path $resultProcess | Should Be @($script:mockProcess2) - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 -Scope It } - + Mock -CommandName Get-Process -MockWith { return @($script:mockProcess1) } Mock -CommandName Get-CimInstance -MockWith { return $script:mockProcess1 } @@ -484,11 +489,11 @@ try $resultProcess = Get-ProcessCimInstance -Path $script:mockProcess1.Path ` -Arguments $script:mockProcess1.Arguments $resultProcess | Should Be @($script:mockProcess1) - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 -Scope It } - + $expectedProcesses = @($script:mockProcess1, $script:mockProcess1, $script:mockProcess1) Mock -CommandName Get-Process -MockWith { return $expectedProcesses } Mock -CommandName Get-CimInstance -MockWith { return $script:mockProcess1 } @@ -496,13 +501,13 @@ try It 'Should return the correct processes when multiple exist' { $resultProcess = Get-ProcessCimInstance -Path $script:mockProcess1.Path ` -Arguments $script:mockProcess1.Arguments - + Compare-Object -ReferenceObject $expectedProcesses -DifferenceObject $resultProcess | Should Be $null - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 3 -Scope It } - + Mock -CommandName Get-Process -MockWith { return @($script:mockProcess2, $script:mockProcess2) } Mock -CommandName Get-CimInstance -MockWith { return @($script:mockProcess2, $script:mockProcess2) } @@ -511,11 +516,11 @@ try -Arguments $script:mockProcess2.Arguments ` -UseGetCimInstanceThreshold 1 $resultProcess | Should Be @($script:mockProcess2, $script:mockProcess2) - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 -Scope It } - + Mock -CommandName Get-Process -MockWith { return @($script:mockProcess2) } Mock -CommandName Get-CimInstance -MockWith { return $script:mockProcess2 } Mock -CommandName Get-ProcessOwner -MockWith { return ($env:computerName + '\' + $script:testUsername) } ` @@ -525,12 +530,12 @@ try $resultProcess = Get-ProcessCimInstance -Path $script:mockProcess2.Path ` -Credential $script:testCredential $resultProcess | Should Be @($script:mockProcess2) - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-ProcessOwner -Exactly 1 -Scope It } - + Mock -CommandName Get-Process -MockWith { return @($script:mockProcess3, $script:mockProcess3, $script:mockProcess4, $script:mockProcess2) } Mock -CommandName Get-CimInstance -MockWith { return @($script:mockProcess3, $script:mockProcess3, $script:mockProcess4, $script:mockProcess2) } Mock -CommandName Get-ProcessOwner -MockWith { return ($env:computerName + '\' + $script:testUsername) } ` @@ -544,11 +549,11 @@ try -Arguments $script:mockProcess3.Arguments ` -UseGetCimInstanceThreshold 1 $resultProcess | Should Be @($script:mockProcess3, $script:mockProcess3) - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 -Scope It } - + Mock -CommandName Get-ProcessOwner -MockWith { return ($env:computerName + '\' + $script:testUsername) } ` -ParameterFilter { ($Process -eq $script:mockProcess3) -or ($Process -eq $script:mockProcess2) } Mock -CommandName Get-ProcessOwner -MockWith { return ('wrongDomain' + '\' + $script:testUsername) } ` @@ -560,26 +565,26 @@ try -Arguments $script:mockProcess3.Arguments ` -UseGetCimInstanceThreshold 1 $resultProcess | Should Be @($script:mockProcess3, $script:mockProcess3) - + Assert-MockCalled -CommandName Get-Process -Exactly 1 -Scope It Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 -Scope It } } - + Describe 'xWindowsProcess\ConvertTo-EscapedStringForWqlFilter' { It 'Should return the same string when there are no escaped characters' { $inputString = 'testString%$.@123' $convertedString = ConvertTo-EscapedStringForWqlFilter -FilterString $inputString $convertedString | Should Be $inputString } - + It 'Should return a string with escaped characters: ("\)' { $inputString = '\test"string"\123' $expectedString = '\\test\"string\"\\123' $convertedString = ConvertTo-EscapedStringForWqlFilter -FilterString $inputString $convertedString | Should Be $expectedString } - + It "Should return a string with escaped characters: ('\)" { $inputString = "\test'string'\123" $expectedString = "\\test\'string\'\\123" @@ -587,47 +592,47 @@ try $convertedString | Should Be $expectedString } } - + Describe 'xWindowsProcess\Get-ProcessOwner' { $mockOwner = @{ Domain = 'Mock Domain' User = 'Mock User' - } + } Mock -CommandName Get-ProcessOwnerCimInstance -MockWith { return $mockOwner } It 'Should return the correct string with domain\user' { $owner = Get-ProcessOwner -Process $script:mockProcess1 $owner | Should Be ($mockOwner.Domain + '\' + $mockOwner.User) } - + It 'Should return the correct string with default-domain\user when domain is not there' { $mockOwner.Domain = $null $owner = Get-ProcessOwner -Process $script:mockProcess1 $owner | Should Be ($env:computerName + '\' + $mockOwner.User) } - + } - - Describe 'xWindowsProcess\Get-ArgumentsFromCommandLineInput' { + + Describe 'xWindowsProcess\Get-ArgumentsFromCommandLineInput' { It 'Should return the correct arguments when single quotes are used' { $inputString = 'test.txt a b c' $argumentsReturned = Get-ArgumentsFromCommandLineInput -CommandLineInput $inputString $argumentsReturned | Should Be 'a b c' } - + It 'Should return the correct arguments when double quotes are used' { $inputString = '"test file test" a b c' $argumentsReturned = Get-ArgumentsFromCommandLineInput -CommandLineInput $inputString $argumentsReturned | Should Be 'a b c' } - + It 'Should return an empty string when an empty string is passed in' { $inputString = $null $resultString = [String]::Empty $argumentsReturned = Get-ArgumentsFromCommandLineInput -CommandLineInput $inputString $argumentsReturned | Should Be $resultString } - + It 'Should return an empty string when there are no arguments' { $inputString = 'test.txt' $resultString = [String]::Empty @@ -635,7 +640,7 @@ try $argumentsReturned | Should Be $resultString } } - + Describe 'xWindowsProcess\Assert-HashtableDoesNotContainKey' { $mockHashtable = @{ Key1 = 'test key1' @@ -643,23 +648,23 @@ try Key3 = 'test key3' } Mock -CommandName New-InvalidArgumentException -MockWith { Throw $script:exceptionMessage } - + It 'Should not throw an exception if the hashtable does not contain a key' { $mockKey = @('k1', 'k2', 'k3', 'k4', 'k5') { Assert-HashTableDoesNotContainKey -Hashtable $mockHashtable -Key $mockKey } | Should Not Throw } - + It 'Should throw an exception if the hashtable contains a key' { $mockKey = @('k1', 'k2', 'Key3', 'k4', 'k5') { Assert-HashTableDoesNotContainKey -Hashtable $mockHashtable -Key $mockKey } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } } - + Describe 'xWindowsProcess\Wait-ProcessCount' { - $mockProcessSettings = @{ - Path = 'mockPath' + $mockProcessSettings = @{ + Path = 'mockPath' Arguments = 'mockArguments' } Mock -CommandName Get-ProcessCimInstance -MockWith { return @($script:mockProcess1, $script:mockProcess3) } @@ -668,7 +673,7 @@ try $processCountResult = Wait-ProcessCount -ProcessSettings $mockProcessSettings -ProcessCount 2 $processCountResult | Should Be $true } - + It 'Should return false when not all processes are returned' { $processCountResult = Wait-ProcessCount -ProcessSettings $mockProcessSettings ` -ProcessCount 3 ` @@ -676,48 +681,48 @@ try $processCountResult | Should Be $false } } - + Describe 'xWindowsProcess\Assert-PathArgumentRooted' { Mock -CommandName New-InvalidArgumentException -MockWith { Throw $script:exceptionMessage } It 'Should not throw when path is rooted' { $rootedPath = 'C:\testProcess.exe' - + { Assert-PathArgumentRooted -PathArgumentName 'mock test name' ` -PathArgument $rootedPath } | Should Not Throw } - + It 'Should throw an invalid argument exception when Path is unrooted' { $unrootedPath = 'invalidfile.txt' - - + + { Assert-PathArgumentRooted -PathArgumentName 'mock test name' ` -PathArgument $unrootedPath } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } } - + Describe 'xWindowsProcess\Assert-PathArgumentValid' { Mock -CommandName New-InvalidArgumentException -MockWith { Throw $script:exceptionMessage } It 'Should not throw when path is valid' { Mock -CommandName Test-Path -MockWith { return $true } - + { Assert-PathArgumentValid -PathArgumentName 'test name' ` -PathArgument 'validPath' } | Should Not Throw } - + It 'Should throw an invalid argument exception when Path is not valid' { Mock -CommandName Test-Path -MockWith { return $false } - + { Assert-PathArgumentValid -PathArgumentName 'test name' ` -PathArgument 'invalidPath' } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } } - + Describe 'xWindowsProcess\Split-Credential' { Mock -CommandName New-InvalidArgumentException -MockWith { Throw $script:exceptionMessage } @@ -725,57 +730,57 @@ try $testUsername = 'user@domain' $testPassword = ConvertTo-SecureString -String 'dummy' -AsPlainText -Force $testCredential = New-Object -TypeName 'PSCredential' -ArgumentList @($testUsername, $testPassword) - + $splitCredentialResult = Split-Credential -Credential $testCredential - + $splitCredentialResult.Domain | Should Be 'domain' $splitCredentialResult.Username | Should Be 'user' } - + It 'Should return correct domain and username with \ seperator' { $testUsername = 'domain\user' $testPassword = ConvertTo-SecureString -String 'dummy' -AsPlainText -Force $testCredential = New-Object -TypeName 'PSCredential' -ArgumentList @($testUsername, $testPassword) - + $splitCredentialResult = Split-Credential -Credential $testCredential - + $splitCredentialResult.Domain | Should Be 'domain' $splitCredentialResult.Username | Should Be 'user' } - + It 'Should return correct domain and username with a local user' { $testUsername = 'localuser' $testPassword = ConvertTo-SecureString -String 'dummy' -AsPlainText -Force $testCredential = New-Object -TypeName 'PSCredential' -ArgumentList @($testUsername, $testPassword) - + $splitCredentialResult = Split-Credential -Credential $testCredential - + $splitCredentialResult.Domain | Should Be $env:computerName $splitCredentialResult.Username | Should Be 'localuser' } - + It 'Should throw an invalid argument exception when more than one \ in username' { $testUsername = 'user\domain\foo' $testPassword = ConvertTo-SecureString -String 'dummy' -AsPlainText -Force $testCredential = New-Object -TypeName 'PSCredential' -ArgumentList @($testUsername, $testPassword) - + { $splitCredentialResult = Split-Credential -Credential $testCredential } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } - + It 'Should throw an invalid argument exception when more than one @ in username' { $testUsername = 'user@domain@foo' $testPassword = ConvertTo-SecureString -String 'dummy' -AsPlainText -Force $testCredential = New-Object -TypeName 'PSCredential' -ArgumentList @($testUsername, $testPassword) - + { $splitCredentialResult = Split-Credential -Credential $testCredential } | Should Throw $script:exceptionMessage - + Assert-MockCalled -CommandName New-InvalidArgumentException -Exactly 1 -Scope It } } - } -} + } +} finally { Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 0e2faef9a..51851644c 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -4,6 +4,14 @@ param () $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +Import-Module -Name (Join-Path -Path (Split-Path $PSScriptRoot -Parent) ` + -ChildPath 'CommonTestHelper.psm1') + +if (Test-SkipContinuousIntegrationTask -Type 'Unit') +{ + return +} + $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' diff --git a/appveyor.yml b/appveyor.yml index 24642527f..ff0881da1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,32 @@ version: 6.0.{build}.0 environment: gallery_api: secure: 9ekJzfsPCDBkyLrfmov83XbbhZ6E2N3z+B/Io8NbDetbHc6hWS19zsDmy7t0Vvxv + # The job where deploy step should run (normally the last job) + DeployInJobNumber: 5 + +# The images that will be used when building the job matrix. +image: +- Visual Studio 2017 +- Visual Studio 2015 + +# The configuration that will be used when building the job matrix. +# Meta = Test Framework Common Test +# Unit = Module Unit Tests. +# Integration = Module Integration Tests. +configuration: +- Meta +- Unit +- Integration + +# - If one job in the matrix fails, the build will stop (fast_finish). +# - The jobs that will excluded based on the combination of configuration name +# and image name. This will make sure the meta tests (common tests) are only +# run on one of the images. +matrix: + fast_finish: true + exclude: + - configuration: Meta + image: Visual Studio 2015 install: - git clone https://github.com/PowerShell/DscResource.Tests @@ -23,15 +49,78 @@ build: false # test configuration # #---------------------------------# -test_script: +# This will build the job matrix (exception is what is excluded from the matrix +# above). The jobs will be order by the order of key 'configuration:' and then +# by the key 'images:'. +# +# Job 1: Run meta test (common tests) on image Visual Studio 2017. +# Job 2: Run unit tests on image Visual Studio 2017, including Codecov report. +# Job 3: Run integration tests on image Visual Studio 2017. +# Job 4: Run unit tests on image Visual Studio 2015, without Codecov report. +# Job 5: Run integration tests on image Visual Studio 2015. + +for: +- + # Job 1. + matrix: + only: + - configuration: Meta + + test_script: + - ps: | + Invoke-AppveyorTestScriptTask ` + -Type 'Default' ` + -ExcludeTag @() + +- + # Job 3 and job 5. + matrix: + only: + - configuration: Integration + environment: + SkipAllCommonTests: True + + test_script: + - ps: | + Invoke-AppveyorTestScriptTask ` + -Type 'Default' ` + -DisableConsistency ` + -ExcludeTag @() + +- + # Job 4. + matrix: + only: + - configuration: Unit + image: Visual Studio 2015 + environment: + SkipAllCommonTests: True + + test_script: + - ps: | + Invoke-AppveyorTestScriptTask ` + -Type 'Default' ` + -CodeCoverage ` + -ExcludeTag @() + +- + # Job 2. + matrix: + only: + - configuration: Unit + image: Visual Studio 2017 + environment: + SkipAllCommonTests: True + + test_script: - ps: | Invoke-AppveyorTestScriptTask ` -Type 'Default' ` -CodeCoverage ` -CodeCovIo ` - -DisableConsistency ` -ExcludeTag @() +# Runs for all jobs. after_test: - ps: | Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" @@ -42,6 +131,14 @@ after_test: # deployment configuration # #---------------------------------# +# Runs only in a branch (not in PR). deploy_script: - ps: | - Invoke-AppVeyorDeployTask + if ($env:APPVEYOR_JOB_NUMBER -eq $env:DeployInJobNumber) + { + Invoke-AppVeyorDeployTask + } + else + { + Write-Verbose -Message ('Skipping deploy step. Deploy step was requested to run in job number {0}. Current job number is {1}.' -f $env:DeployInJobNumber, $env:APPVEYOR_JOB_NUMBER) -Verbose + }