Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveDirectoryDsc: Split tests in different AppVeyor jobs #479

Merged
merged 30 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c5f1d98
Update appveyor.yml to separate testing by jobs
johlju Aug 8, 2019
4777691
Add category to unit test
johlju Aug 8, 2019
ca65cbf
Update tests
johlju Aug 8, 2019
e27956f
Add stub for class Microsoft.ActiveDirectory.Management.ADException
johlju Aug 8, 2019
a3173a0
Fix tests in Common
johlju Aug 8, 2019
db52aa4
Fix ADDomain
johlju Aug 8, 2019
9bbfbbc
Fix unit tests
johlju Aug 8, 2019
d604c76
Update test for ADDomainController
johlju Aug 8, 2019
c6c0c03
Fix MSFT_ADDomainDefaultPasswordPolicy
johlju Aug 8, 2019
44fe9bb
Fix ADForestProperties
johlju Aug 9, 2019
ae728f9
Exchange parameter alias name with real parameter name
johlju Aug 9, 2019
5b953d9
Fix ADGroup tests
johlju Aug 9, 2019
b7c3953
Update ADKDSKey
johlju Aug 9, 2019
eaca3d9
Exchange alias Property with real parameter name
johlju Aug 9, 2019
a2e5c36
Fix unit test for ADMangedServiceAccount
johlju Aug 9, 2019
77146be
Fix ADObjectEnabledState
johlju Aug 9, 2019
0c4dac1
Fix ADObjectPermissionEntry
johlju Aug 9, 2019
1a9e30e
Update TestHelper
johlju Aug 9, 2019
f62d870
Fix ADReplicationSite
johlju Aug 9, 2019
34c29ba
Fix ADReplicationSiteLink
johlju Aug 9, 2019
d8eac03
Fix ADReplicationSubnet
johlju Aug 9, 2019
c73ef1c
Fix ADServicePrincipalName
johlju Aug 9, 2019
d45862e
Fix ADUser
johlju Aug 9, 2019
41c5cc1
Fix ADOptionalFeature
johlju Aug 9, 2019
2749813
Add back unit test for ADDomainFunctionalLevel
johlju Aug 9, 2019
a973851
Update CHANGELOG.md
johlju Aug 9, 2019
b6a60b9
Add SupportsShouldProcess on Remove-ADServiceAccount
johlju Aug 9, 2019
fc61aa6
Update CHANGELOG.md
johlju Aug 9, 2019
84a167c
Update conceptual help
johlju Aug 9, 2019
4d0efbe
Fix review comments at r1
johlju Aug 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
- New resource ADDomainControllerProperties ([issue #301](https://github.com/PowerShell/ActiveDirectoryDsc/issues/301)).
- New resource ADForestFunctionalLevel ([issue #200](https://github.com/PowerShell/ActiveDirectoryDsc/issues/200)).
- New resource ADDomainFunctionalLevel ([issue #200](https://github.com/PowerShell/ActiveDirectoryDsc/issues/200)).
- Changes to xWaitforADDomain
- Split the meta tests and the unit and integration tests in different
AppVeyor jobs ([issue #437](https://github.com/PowerShell/ActiveDirectoryDsc/issues/437)).
- Fixed all stub cmdlets and unit tests so the unit test can be run locally
without having the ActiveDirectory module installed on the computer.
This will also be reflected in the AppVeyor build worker where there
will no longer be an ActiveDirectory module installed. This is
to make sure that if the unit tests work locally they should also work
in the CI pipeline.
- Changes to xWaitForADDomain
- Correct Grammar Issues in Example Descriptions.

## 4.0.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function Get-TargetResource
[System.Management.Automation.CredentialAttribute()]
$Credential
)

Assert-Module -ModuleName 'ActiveDirectory'

$PSBoundParameters['Identity'] = $DomainName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ADDomainFunctionalLevel

.DESCRIPTION
This resource change the forest functional level. Functional levels can
This resource change the domain functional level. Functional levels can
be read more about in the article [Forest and Domain Functional Levels](https://docs.microsoft.com/sv-se/windows-server/identity/ad-ds/active-directory-functional-levels).

**WARNING: This action might be irreversibel!** Make sure to understand
Expand All @@ -15,6 +15,8 @@
## Requirements

* Target machine must be running Windows Server 2008 R2 or later.
* Target machine must be running the minimum required operating system
version for the domain functional level to set.

.PARAMETER DomainIdentity
Key - String
Expand All @@ -30,13 +32,13 @@
This configuration will change the domain functional level to
a Windows Server 2012 R2 Domain.

Configuration ADDomainControllerProperties_SetContentFreshness_Config
Configuration ADDomainFunctionalLevel_SetLevel_Config
{
Import-DscResource -ModuleName ActiveDirectoryDsc

node localhost
{
ADDomainControllerProperties 'ChangeForestFunctionalLevel'
ADDomainFunctionalLevel 'ChangeDomainFunctionalLevel'
{
DomainIdentity = 'contoso.com'
DomainMode = 'Windows2012R2Domain'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
## Requirements

* Target machine must be running Windows Server 2008 R2 or later.
* Target machine must be running the minimum required operating system
version for the forest functional level to set.

.PARAMETER ForestIdentity
Key - String
Expand All @@ -23,20 +25,20 @@
.PARAMETER ForestMode
Required - String
Allowed values: Windows2008R2Forest, Windows2012Forest, Windows2012R2Forest, Windows2016Forest
Specifies the the functional level for the Active Directory forest..
Specifies the the functional level for the Active Directory forest.

.EXAMPLE 1

This configuration will change the forest functional level to
a Windows Server 2012 R2 Forest.

Configuration ADDomainControllerProperties_SetContentFreshness_Config
Configuration ADForestFunctionalLevel_SetLevel_Config
{
Import-DscResource -ModuleName ActiveDirectoryDsc

node localhost
{
ADDomainControllerProperties 'ChangeForestFunctionalLevel'
ADForestFunctionalLevel 'ChangeForestFunctionalLevel'
{
ForestIdentity = 'contoso.com'
ForestMode = 'Windows2012R2Forest'
Expand Down
22 changes: 20 additions & 2 deletions DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ function Get-TargetResource

try
{
$adGroup = Get-ADGroup @adGroupParams -Property Name, GroupScope, GroupCategory, DistinguishedName, Description, DisplayName, ManagedBy, Info
$adGroup = Get-ADGroup @adGroupParams -Properties @(
'Name',
'GroupScope',
'GroupCategory',
'DistinguishedName',
'Description',
'DisplayName',
'ManagedBy',
'Info'
)

Write-Verbose -Message ($script:localizedData.RetrievingGroupMembers -f $MembershipAttribute)

Expand Down Expand Up @@ -595,7 +604,16 @@ function Set-TargetResource
}
}

$adGroup = Get-ADGroup @adGroupParams -Property Name, GroupScope, GroupCategory, DistinguishedName, Description, DisplayName, ManagedBy, Info
$adGroup = Get-ADGroup @adGroupParams -Properties @(
'Name',
'GroupScope',
'GroupCategory',
'DistinguishedName',
'Description',
'DisplayName',
'ManagedBy',
'Info'
)

if ($Ensure -eq 'Present')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Get-TargetResource
{
Write-Verbose -Message ($script:localizedData.RetrievingServiceAccount -f $ServiceAccountName)

$adServiceAccount = Get-ADServiceAccount @adServiceAccountParameters -Property @(
$adServiceAccount = Get-ADServiceAccount @adServiceAccountParameters -Properties @(
'Name'
'DistinguishedName'
'Description'
Expand Down Expand Up @@ -117,7 +117,7 @@ function Get-TargetResource
Write-Verbose -Message ($script:localizedData.RetrievingPrincipalMembers -f $MembershipAttribute)
$adServiceAccount.PrincipalsAllowedToRetrieveManagedPassword |
ForEach-Object {
$member = (Get-ADObject -Identity $_ -Property $MembershipAttribute).$MembershipAttribute
$member = (Get-ADObject -Identity $_ -Properties $MembershipAttribute).$MembershipAttribute
$targetResource['Members'] += $member
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

This configuration will wait for an Active Directory domain controller
to respond within 300 seconds (default) in the domain 'contoso.com'
before returning and allowing the configuration to continue run.
before returning and allowing the configuration to continue to run.
If the timeout is reached an error will be thrown.
This will use the current user when determining if the domain is available,
if run though LCM this will use SYSTEM (which might not have access).
Expand All @@ -67,9 +67,9 @@ Configuration WaitForADDomain_WaitForDomainController_Config

This configuration will wait for an Active Directory domain controller
to respond within 300 seconds (default) in the domain 'contoso.com'
before returning and allowing the configuration to continue run.
before returning and allowing the configuration to continue to run.
If the timeout is reached an error will be thrown.
This will use the user credential passes to the built-in PsDscRunAsCredential
This will use the user credential passed in the built-in PsDscRunAsCredential
parameter when determining if the domain is available.

Configuration WaitForADDomain_WaitForDomainControllerUsingBuiltInCredential_Config
Expand Down Expand Up @@ -99,9 +99,9 @@ Configuration WaitForADDomain_WaitForDomainControllerUsingBuiltInCredential_Conf

This configuration will wait for an Active Directory domain controller
to respond within 300 seconds (default) in the domain 'contoso.com'
before returning and allowing the configuration to continue run.
before returning and allowing the configuration to continue to run.
If the timeout is reached an error will be thrown.
This will use the user credential passes to the parameter Credential
This will use the user credential passed in the parameter Credential
when determining if the domain is available.

Configuration WaitForADDomain_WaitForDomainControllerUsingCredential_Config
Expand Down Expand Up @@ -131,9 +131,9 @@ Configuration WaitForADDomain_WaitForDomainControllerUsingCredential_Config
This configuration will wait for an Active Directory domain controller
in the site 'Europe' to respond within 300 seconds (default) in the
domain 'contoso.com' before returning and allowing the configuration to
continue run.
continue to run.
If the timeout is reached an error will be thrown.
This will use the user credential passes to the built-in PsDscRunAsCredential
This will use the user credential passed in the built-in PsDscRunAsCredential
parameter when determining if the domain is available.

Configuration WaitForADDomain_WaitForDomainControllerInSite_Config
Expand Down Expand Up @@ -164,11 +164,11 @@ Configuration WaitForADDomain_WaitForDomainControllerInSite_Config

This configuration will wait for an Active Directory domain controller
to respond within 300 seconds (default) in the domain 'contoso.com'
before returning and allowing the configuration to continue run.
before returning and allowing the configuration to continue to run.
If the timeout is reached the node will be restarted up to two times
and again wait after each restart. If the no domain controller is found
and again wait after each restart. If no domain controller is found
after the second restart an error will be thrown.
This will use the user credential passes to the built-in PsDscRunAsCredential
This will use the user credential passed in the built-in PsDscRunAsCredential
parameter when determining if the domain is available.

Configuration WaitForADDomain_WaitForDomainControllerWithReboot_Config
Expand All @@ -187,9 +187,9 @@ Configuration WaitForADDomain_WaitForDomainControllerWithReboot_Config
{
WaitForADDomain 'contoso.com'
{
DomainName = 'contoso.com'
DomainName = 'contoso.com'
RestartCount = 2

PsDscRunAsCredential = $Credential
}
}
Expand All @@ -199,9 +199,9 @@ Configuration WaitForADDomain_WaitForDomainControllerWithReboot_Config

This configuration will wait for an Active Directory domain controller
to respond within 600 seconds in the domain 'contoso.com' before
returning and allowing the configuration to continue run. If the timeout
returning and allowing the configuration to continue to run. If the timeout
is reached an error will be thrown.
This will use the user credential passes to the built-in PsDscRunAsCredential
This will use the user credential passed in the built-in PsDscRunAsCredential
parameter when determining if the domain is available.

Configuration WaitForADDomain_WaitForDomainControllerWithLongerDelay_Config
Expand All @@ -220,7 +220,7 @@ Configuration WaitForADDomain_WaitForDomainControllerWithLongerDelay_Config
{
WaitForADDomain 'contoso.com'
{
DomainName = 'contoso.com'
DomainName = 'contoso.com'
WaitTimeout = 600

PsDscRunAsCredential = $Credential
Expand Down
91 changes: 91 additions & 0 deletions Tests/TestHelpers/ActiveDirectoryDsc.TestHelper.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<#
.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.

.PARAMETER Category
Optional. One or more categories to check if they are set in
$env:CONFIGURATION. If this are not set, the parameter Type
is used as category.
#>
function Test-RunForCITestCategory
{
[OutputType([System.Boolean])]
[CmdletBinding()]
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$Name = $MyInvocation.PSCommandPath.Split('\')[-1],

[Parameter(Mandatory = $true)]
[ValidateSet('Unit', 'Integration')]
[System.String]
$Type,

[Parameter()]
[System.String[]]
$Category
)

# Support the use of having the Type parameter as the only category names.
if (-not $Category)
{
$Category = @($Type)
}

$result = $true

if ($Type -eq 'Integration' -and -not $env:CI -eq $true)
{
Write-Warning -Message ('{0} test for {1} will be skipped unless $env:CI is set to $true' -f $Type, $Name)
$result = $false
}

if (-not (Test-ContinuousIntegrationTaskCategory -Category $Category))
{
Write-Verbose -Message ('Tests in category ''{0}'' will be skipped unless $env:CONFIGURATION is set to ''{0}''.' -f ($Category -join ''', or '''), $Name) -Verbose
$result = $false
}

return $result
}

<#
.SYNOPSIS
Returns $true if the the environment variable CI is set to $true,
and the environment variable CONFIGURATION is set to the value passed
in the parameter Type.

.PARAMETER Category
One or more categories to check if they are set in $env:CONFIGURATION.
#>
function Test-ContinuousIntegrationTaskCategory
{
[OutputType([System.Boolean])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String[]]
$Category
)

$result = $true

if ($env:CI -eq $true -and $env:CONFIGURATION -notin $Category)
{
$result = $false
}

return $result
}
32 changes: 21 additions & 11 deletions Tests/Unit/ActiveDirectory.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,35 @@
#>
Get-Module -Name 'ActiveDirectoryDsc.Common' -All | Remove-Module -Force

Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1')

if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests'))
{
return
}

# Import the ActiveDirectoryDsc.Common module to test
$script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent
$script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules\ActiveDirectoryDsc.Common'

Import-Module -Name (Join-Path -Path $script:modulesFolderPath -ChildPath 'ActiveDirectoryDsc.Common.psm1') -Force

# If one type does not exist, it's assumed the other ones does not exist either.
if (-not ('Microsoft.DirectoryServices.Deployment.Types.ForestMode' -as [Type]))
{
Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.DirectoryServices.Deployment.Types.cs')
}
InModuleScope 'ActiveDirectoryDsc.Common' {
#Load the AD Module Stub, so we can mock the cmdlets, then load the AD types
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force

# If one type does not exist, it's assumed the other ones does not exist either.
if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type]))
{
Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs')
}
# If one type does not exist, it's assumed the other ones does not exist either.
if (-not ('Microsoft.DirectoryServices.Deployment.Types.ForestMode' -as [Type]))
{
Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.DirectoryServices.Deployment.Types.cs')
}

# If one type does not exist, it's assumed the other ones does not exist either.
if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type]))
{
Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs')
}

InModuleScope 'ActiveDirectoryDsc.Common' {
Describe 'ActiveDirectoryDsc.Common\Test-DscParameterState' -Tag TestDscParameterState {
Context 'When passing values' {
It 'Should return true for two identical tables' {
Expand Down
7 changes: 7 additions & 0 deletions Tests/Unit/MSFT_ADComputer.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1')

if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests'))
{
return
}

$script:dscModuleName = 'ActiveDirectoryDsc'
$script:dscResourceName = 'MSFT_ADComputer'

Expand Down
Loading