Fix Unit Tests and Official Releases (#1854)

* Update Unit Tests

* Update pester from 4 to 5

* Update compile and releases

* Working on making release tags

* Update release.yaml

* Compile Winutil

---------

Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
This commit is contained in:
Chris Titus
2024-04-20 18:30:38 -05:00
committed by GitHub
parent 88a622c368
commit 9eceae6751
4 changed files with 5588 additions and 5563 deletions

View File

@ -1,44 +1,55 @@
#===========================================================================
# Tests - Functions
#===========================================================================
# Get all .ps1 files in the functions folder
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1
# Loop through each file
foreach ($file in $ps1Files) {
# Define the test name
$testName = "Syntax check for $($file.Name)"
# Define the test script
$testScript = {
# Import the script
. $file.FullName
# Check if any errors occurred
$scriptError = $error[0]
$scriptError | Should -Be $null
Describe "Comprehensive Checks for PS1 Files in Functions Folder" {
BeforeAll {
# Get all .ps1 files in the functions folder
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1 -Recurse
}
# Add the test to the Pester test suite
Describe $testName $testScript
}
Describe "Functions"{
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
context "$($psitem.BaseName)" {
BeforeEach -Scriptblock {
. $psitem.FullName
foreach ($file in $ps1Files) {
Context "Checking $($file.Name)" {
It "Should import without errors" {
{ . $file.FullName } | Should -Not -Throw
}
It "Imports with no errors" -TestCases @{
basename = $($psitem.BaseName)
fullname = $psitem.FullName
} {
Get-ChildItem function:\$basename | Should -Not -BeNullOrEmpty
}
It "Should have no syntax errors" {
$syntaxErrors = $null
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $file.FullName -Raw), [ref]$syntaxErrors)
$syntaxErrors.Count | Should -Be 0
}
It "Should not use deprecated cmdlets or aliases" {
$content = Get-Content -Path $file.FullName -Raw
# Example check for a known deprecated cmdlet or alias
$content | Should -Not -Match 'DeprecatedCmdlet'
# Add more checks as needed
}
It "Should follow naming conventions for functions" {
$functions = (Get-Command -Path $file.FullName).Name
foreach ($function in $functions) {
$function | Should -Match '^[a-z]+(-[a-z]+)*$' # Enforce lower-kebab-case
}
}
It "Should define mandatory parameters for all functions" {
. $file.FullName
$functions = (Get-Command -Path $file.FullName).Name
foreach ($function in $functions) {
$parameters = (Get-Command -Name $function).Parameters.Values
$mandatoryParams = $parameters | Where-Object { $_.Attributes.Mandatory -eq $true }
$mandatoryParams.Count | Should -BeGreaterThan 0
}
}
It "Should have all functions available after import" {
. $file.FullName
$functions = (Get-Command -Path $file.FullName).Name
foreach ($function in $functions) {
{ Get-Command -Name $function -CommandType Function } | Should -Not -BeNullOrEmpty
}
}
}
}
}
}