mirror of
https://github.com/EvotecIT/GPOZaurr.git
synced 2026-07-26 11:49:17 +00:00
59 lines
2.4 KiB
PowerShell
59 lines
2.4 KiB
PowerShell
$ModuleName = (Get-ChildItem $PSScriptRoot\*.psd1).BaseName
|
|
$PrimaryModule = Get-ChildItem -Path $PSScriptRoot -Filter '*.psd1' -Recurse -ErrorAction SilentlyContinue -Depth 1
|
|
if (-not $PrimaryModule) {
|
|
throw "Path $PSScriptRoot doesn't contain PSD1 files. Failing tests."
|
|
}
|
|
if ($PrimaryModule.Count -ne 1) {
|
|
throw 'More than one PSD1 files detected. Failing tests.'
|
|
}
|
|
$PSDInformation = Import-PowerShellDataFile -Path $PrimaryModule.FullName
|
|
$RequiredModules = @(
|
|
'Pester'
|
|
'PSWriteColor'
|
|
'PSParseHTML'
|
|
if ($PSDInformation.RequiredModules) {
|
|
$PSDInformation.RequiredModules
|
|
}
|
|
)
|
|
foreach ($Module in $RequiredModules) {
|
|
if ($Module -is [System.Collections.IDictionary]) {
|
|
$Exists = Get-Module -ListAvailable -Name $Module.ModuleName
|
|
if (-not $Exists) {
|
|
Write-Warning "$ModuleName - Downloading $($Module.ModuleName) from PSGallery"
|
|
Install-Module -Name $Module.ModuleName -Force -SkipPublisherCheck
|
|
}
|
|
} else {
|
|
$Exists = Get-Module -ListAvailable $Module -ErrorAction SilentlyContinue
|
|
if (-not $Exists) {
|
|
Install-Module -Name $Module -Force -SkipPublisherCheck
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Color 'ModuleName: ', $ModuleName, ' Version: ', $PSDInformation.ModuleVersion -Color Yellow, Green, Yellow, Green -LinesBefore 2
|
|
Write-Color 'PowerShell Version: ', $PSVersionTable.PSVersion -Color Yellow, Green
|
|
Write-Color 'PowerShell Edition: ', $PSVersionTable.PSEdition -Color Yellow, Green
|
|
Write-Color 'Required modules: ' -Color Yellow
|
|
foreach ($Module in $PSDInformation.RequiredModules) {
|
|
if ($Module -is [System.Collections.IDictionary]) {
|
|
Write-Color ' [>] ', $Module.ModuleName, ' Version: ', $Module.ModuleVersion -Color Yellow, Green, Yellow, Green
|
|
} else {
|
|
Write-Color ' [>] ', $Module -Color Yellow, Green
|
|
}
|
|
}
|
|
Write-Color
|
|
|
|
Import-Module $PSScriptRoot\*.psd1 -Force
|
|
Import-Module Pester -Force
|
|
$Configuration = [PesterConfiguration]::Default
|
|
$Configuration.Run.Path = "$PSScriptRoot\Tests"
|
|
$Configuration.Run.Exit = $true
|
|
$Configuration.Should.ErrorAction = 'Continue'
|
|
$Configuration.CodeCoverage.Enabled = $false
|
|
$Configuration.Output.Verbosity = 'Detailed'
|
|
$Result = Invoke-Pester -Configuration $Configuration
|
|
#$result = Invoke-Pester -Script $PSScriptRoot\Tests -Verbose -Output Detailed #-EnableExit
|
|
|
|
if ($Result.FailedCount -gt 0) {
|
|
throw "$($Result.FailedCount) tests failed."
|
|
} |