forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SqlServerDsc: Unit tests are run in containers (dsccommunity#1236)
- Changes to SqlServerDsc - Updated the Contributing section in the README.md after Style Guideline and Best Practices guidelines has merged into one document. - To speed up testing in AppVeyor, unit tests are now run in two containers. - Adding the PowerShell script `Assert-TestEnvironment.ps1` which must be run prior to running any unit tests locally with `Invoke-Pester`. Read more in the specific contributing guidelines, under the section Unit Tests in the CONTRIBUTING.md.
- Loading branch information
Showing
40 changed files
with
658 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
DSCResource.Tests | ||
DscResource.Tests | ||
DSCResource.Tests | ||
.vs | ||
.vscode | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<# | ||
.SYNOPSIS | ||
Assert that the test environment is properly setup and loaded into the | ||
PowerShell session. | ||
.DESCRIPTION | ||
Assert that the test environment is properly setup and loaded into the | ||
PowerShell session. | ||
.EXAMPLE | ||
.\Assert-testEnvironment.ps1 | ||
Will assert that the current PowerShell session is ready to run tests. | ||
#> | ||
|
||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param | ||
( | ||
) | ||
|
||
#region Verify prerequisites Pester | ||
$pesterModuleName = 'Pester' | ||
|
||
# This is the minimum version that can be used with the tests in this repo. | ||
$pesterModuleMinimumVersion = '4.0.2' | ||
|
||
<# | ||
Pester v4.4.0 has a fix for '-Not -Throw' so it shows the actual error | ||
message if an unexpected exception does occur. It will help when debugging | ||
tests. | ||
If no Pester module exist, then use this as the minimum version. | ||
#> | ||
$pesterModuleRecommendedMinimumVersion = '4.4.0' | ||
|
||
$pesterModule = Get-Module $pesterModuleName -ListAvailable -Verbose:$false | | ||
Where-Object -Property 'Version' -GE -Value $pesterModuleMinimumVersion | | ||
Sort-Object -Property 'Version' -Descending | | ||
Select-Object -First 1 | ||
|
||
if (-not $pesterModule) | ||
{ | ||
<# | ||
Not installing the module here because it's not known what scope the | ||
user want (can) to install the module in. | ||
#> | ||
$message = 'Missing a compatible version of the {0} module. Minimum version of {0} module can be ''{2}'', but the recommended minimum version is ''{1}''.' -f $pesterModuleName, $pesterModuleRecommendedMinimumVersion, $pesterModuleMinimumVersion | ||
Write-Warning -Message $message | ||
$dependencyMissing = $true | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message ('A compatible {0} module is already installed (v{1}). If you want to use a newer version of {0} module, please install it manually.' -f $pesterModule.Name, $pesterModule.Version) | ||
} | ||
#endregion Verify prerequisites Pester | ||
|
||
#region Verify prerequisites PSDepend | ||
$psDependModuleName = 'PSDepend' | ||
|
||
# This is the minimum version that can be used with the tests in this repo. | ||
$psDependModuleMinimumVersion = '0.3.0' | ||
$psDependModuleRecommendedMinimumVersion = 'latest' | ||
|
||
$psDependModule = Get-Module $psDependModuleName -ListAvailable -Verbose:$false | | ||
Where-Object -Property 'Version' -GE -Value $psDependModuleMinimumVersion | | ||
Sort-Object -Property 'Version' -Descending | | ||
Select-Object -First 1 | ||
|
||
if (-not $psDependModule) | ||
{ | ||
<# | ||
Not installing the module here because it's not known what scope the | ||
user want (can) to install the module in. | ||
#> | ||
$message = 'Missing a compatible version of the {0} module. Minimum version of {0} module can be ''{2}'', but the recommended minimum version is ''{1}''. Please install {0} module manually, then run this script again.' -f $psDependModuleName, $psDependModuleRecommendedMinimumVersion, $psDependModuleMinimumVersion | ||
Write-Warning -Message $message | ||
$dependencyMissing = $true | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message ('A compatible {0} module is already installed (v{1}). If you want to use a newer version of {0} module, please install it manually.' -f $psDependModule.Name, $psDependModule.Version) | ||
} | ||
#endregion Verify prerequisites PSDepend | ||
|
||
if ($dependencyMissing) | ||
{ | ||
Write-Output -InputObject 'Please install the necessary dependencies manually, then run this script again.' | ||
return | ||
} | ||
|
||
$dependenciesPath = Join-Path $PSScriptRoot -ChildPath 'Tests' | ||
|
||
Write-Verbose -Message ('Running Invoke-PSDepend using dependencies found under the path ''{0}''.' -f $dependenciesPath) | ||
|
||
if ($PSBoundParameters.ContainsKey('Confirm')) | ||
{ | ||
$invokePSDependConfirmation = $ConfirmPreference | ||
} | ||
else | ||
{ | ||
$invokePSDependConfirmation = $false | ||
} | ||
|
||
Invoke-PSDepend -Path $dependenciesPath -Confirm:$invokePSDependConfirmation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<# | ||
.DESCRIPTION | ||
This is the dependency file for use with Assert-TestEnvironment.ps1 and/or | ||
Invoke-PSDepend (PSSDepend). | ||
#> | ||
@{ | ||
RemoveTestFramework = @{ | ||
DependencyType = 'Command' | ||
Source = ' | ||
$testFrameWorkPath = Join-Path -Path $PWD -ChildPath ''DscResource.Tests'' | ||
if (Test-Path -Path $testFrameWorkPath) | ||
{ | ||
Write-Verbose -Message ''Removing local test framework repository.'' | ||
Remove-Item -Path (Join-Path -Path $PWD -ChildPath ''DscResource.Tests'') -Recurse -Force | ||
} | ||
' | ||
} | ||
|
||
'CloneTestFramework' = @{ | ||
DependencyType = 'Git' | ||
Name = 'https://github.com/PowerShell/DscResource.Tests' | ||
Version = 'dev' | ||
DependsOn = 'RemoveTestFramework' | ||
} | ||
|
||
LoadDscResourceKitTypes = @{ | ||
DependencyType = 'Command' | ||
Source = ' | ||
if (-not (''Microsoft.DscResourceKit.Test'' -as [Type])) | ||
{ | ||
Write-Verbose -Message ''Loading the Microsoft.DscResourceKit types into the current session.'' | ||
$typesSourceFile = Join-Path -Path ''$PWD\DscResource.Tests'' -ChildPath ''Microsoft.DscResourceKit.cs'' | ||
Add-Type -Path $typesSourceFile -WarningAction SilentlyContinue | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message ''The Microsoft.DscResourceKit types was already loaded into the current session.'' | ||
} | ||
' | ||
DependsOn = 'CloneTestFramework' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.