forked from dsccommunity/AzureDevOpsDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azuredevopsdsc.tests.ps1
87 lines (63 loc) · 2.66 KB
/
azuredevopsdsc.tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[CmdletBinding()]
param (
[Parameter()]
[switch]
$LoadModulesOnly
)
# Unload the $Global:RepositoryRoot and $Global:TestPaths variables
Remove-Variable -Name RepositoryRoot -Scope Global -ErrorAction SilentlyContinue
# Set the $Global:RepositoryRoot and $Global:TestPaths variables
$Global:RepositoryRoot = $PSScriptRoot
$ClassesDirectory = "$Global:RepositoryRoot\source\Classes"
$EnumsDirectory = "$Global:RepositoryRoot\source\Enum"
$PublicDirectory = "$Global:RepositoryRoot\source\Modules\AzureDevOpsDsc.Common\Resources\Functions\Public"
$Global:ClassesLoaded = $true
#
# Load the Helper Modules
Import-Module -Name (Join-Path -Path $Global:RepositoryRoot -ChildPath 'tests\Unit\Modules\TestHelpers\CommonTestFunctions.psm1')
#
# Load all the Enums
Get-ChildItem -LiteralPath $EnumsDirectory -File | ForEach-Object {
Write-Verbose "Dot Sourcing $($_.FullName)"
. $_.FullName
}
#
# Load all the Classes
Get-ChildItem -LiteralPath $ClassesDirectory -File | ForEach-Object {
Write-Verbose "Dot Sourcing $($_.FullName)"
# Read the file and remove [DscResource()] attribute
$file = Get-Command $_.FullName
# Remove [DscResource()] attribute
$content = $file.ScriptContents -replace '\[DscResource\(\)\]', ''
# Convert the string array into ScriptBlock
$scriptBlock = [ScriptBlock]::Create($content)
# Dot source the script block
. $scriptBlock
}
# Load all the Helper Functions from the AzureDevOpsDsc.Common Module into Memory
Get-ChildItem -LiteralPath "$($Global:RepositoryRoot)\source\Modules\AzureDevOpsDsc.Common\Api\Functions\Private\Helper" -File -Recurse -Filter *.ps1 | ForEach-Object {
Write-Verbose "Dot Sourcing $($_.FullName)"
. $_.FullName
}
# Load all the Public Functions from the AzureDevOpsDsc.Common Module into Memory
Get-ChildItem -LiteralPath $PublicDirectory -File -Recurse -Filter *.ps1 | ForEach-Object {
Write-Verbose "Dot Sourcing $($_.FullName)"
. $_.FullName
}
if ($LoadModulesOnly.IsPresent)
{
return
}
$config = New-PesterConfiguration
$config.Run.Path = ".\tests\Unit\Classes"
$config.Output.CIFormat = "GitHubActions"
#$config.Output.Verbosity = "Detailed"
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = @(
'.\source\Classes\'
)
$config.CodeCoverage.OutputFormat = 'CoverageGutters'
$config.CodeCoverage.OutputPath = ".\output\AzureDevOpsDsc.codeCoverage.xml"
$config.CodeCoverage.OutputEncoding = 'utf8'
# Get the path to the function being tested
Invoke-Pester -Configuration $config