mirror of https://github.com/raandree/NTFSSecurity
Browse Source
- Require Windows PowerShell 5.1 or PowerShell 7 (PowerShellVersion 5.1, which CompatiblePSEditions needs) and .NET Framework 4.5.2, and use RootModule instead of the deprecated ModuleToProcess. Before, Test-ModuleManifest, and with it Publish-Module, failed. - Export exactly the 36 cmdlets: remove Show-NTFSSimpleAccess, which no longer exists, and the duplicate inheritance cmdlets. - Keep -PassThur, the name in 4.2.6 and earlier, as an alias of Remove-Item2 -PassThru, deprecated in the changelog. - Set version 5.0.0 in the manifest, in NTFSSecurity, Security2, and PrivilegeControl, and in a new 5.0.0 section of CHANGELOG.md. - Tests/Manifest.Tests.ps1 and Tests/Remove-Item2.Tests.ps1 guard the manifest, the versions, and the alias. BREAKING CHANGE: the module requires Windows PowerShell 5.1 or PowerShell 7; the manifest no longer claims PowerShell 2.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: AI Assistant <ai@example.com>pull/95/head
10 changed files with 145 additions and 26 deletions
@ -0,0 +1,73 @@ |
|||||
|
<# |
||||
|
Tests the module manifest of the module built in NTFSSecurity\bin\Release: it passes Test-ModuleManifest, |
||||
|
exports exactly the cmdlets of the module, and carries the same version as the assemblies and CHANGELOG.md. |
||||
|
#> |
||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
||||
|
'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester shares variables between blocks.' |
||||
|
)] |
||||
|
param () |
||||
|
|
||||
|
BeforeDiscovery { |
||||
|
# The first-party assemblies of the module carry the module version; ProcessPrivileges is a vendored library. |
||||
|
$versionedAssemblies = 'NTFSSecurity', 'Security2', 'PrivilegeControl' |
||||
|
} |
||||
|
|
||||
|
Describe 'Module manifest of NTFSSecurity' { |
||||
|
BeforeAll { |
||||
|
$manifestPath = Join-Path -Path $PSScriptRoot -ChildPath '..\NTFSSecurity\bin\Release\NTFSSecurity.psd1' |
||||
|
$manifest = Import-PowerShellDataFile -Path $manifestPath |
||||
|
$module = Import-Module -Name $manifestPath -Force -PassThru -ErrorAction Stop | |
||||
|
Where-Object -Property Name -EQ -Value 'NTFSSecurity' |
||||
|
} |
||||
|
|
||||
|
AfterAll { |
||||
|
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue |
||||
|
} |
||||
|
|
||||
|
It 'Should pass Test-ModuleManifest without errors or warnings' { |
||||
|
$testParameters = @{ |
||||
|
Path = $manifestPath |
||||
|
ErrorVariable = 'manifestErrors' |
||||
|
WarningVariable = 'manifestWarnings' |
||||
|
ErrorAction = 'SilentlyContinue' |
||||
|
WarningAction = 'SilentlyContinue' |
||||
|
} |
||||
|
$null = Test-ModuleManifest @testParameters |
||||
|
|
||||
|
@($manifestErrors) + @($manifestWarnings) | ForEach-Object -Process { "$_" } | Should -BeNullOrEmpty |
||||
|
} |
||||
|
|
||||
|
It 'Should list each cmdlet only once in CmdletsToExport' { |
||||
|
$duplicates = $manifest.CmdletsToExport | Group-Object | Where-Object -Property Count -GT -Value 1 |
||||
|
|
||||
|
$duplicates.Name | Should -BeNullOrEmpty |
||||
|
} |
||||
|
|
||||
|
It 'Should list only cmdlets of the module in CmdletsToExport' { |
||||
|
$manifest.CmdletsToExport | Where-Object -FilterScript { -not $module.ExportedCmdlets.ContainsKey($_) } | |
||||
|
Should -BeNullOrEmpty |
||||
|
} |
||||
|
|
||||
|
It 'Should export exactly 36 cmdlets' { |
||||
|
@($manifest.CmdletsToExport) | Should -HaveCount 36 |
||||
|
$module.ExportedCmdlets.Keys | Should -HaveCount 36 |
||||
|
} |
||||
|
|
||||
|
Context 'Version' { |
||||
|
It 'Should give <_>.dll the module version' -ForEach $versionedAssemblies { |
||||
|
$assemblyPath = Join-Path -Path $module.ModuleBase -ChildPath "$_.dll" |
||||
|
$assemblyVersion = [Reflection.AssemblyName]::GetAssemblyName($assemblyPath).Version |
||||
|
$fileVersion = [version] (Get-Item -LiteralPath $assemblyPath).VersionInfo.FileVersion |
||||
|
|
||||
|
$assemblyVersion.ToString(3) | Should -BeExactly $manifest.ModuleVersion |
||||
|
$fileVersion.ToString(3) | Should -BeExactly $manifest.ModuleVersion |
||||
|
} |
||||
|
|
||||
|
It 'Should describe the module version in the latest section of CHANGELOG.md' { |
||||
|
$changelog = Get-Content -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath '..\CHANGELOG.md') -Raw |
||||
|
$latestVersion = [regex]::Match($changelog, '(?m)^## \[(?<Version>\d+\.\d+\.\d+)\]').Groups['Version'].Value |
||||
|
|
||||
|
$latestVersion | Should -BeExactly $manifest.ModuleVersion |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
<# |
||||
|
Tests Remove-Item2 of the module built in NTFSSecurity\bin\Release. |
||||
|
#> |
||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
||||
|
'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester shares variables between blocks.' |
||||
|
)] |
||||
|
param () |
||||
|
|
||||
|
Describe 'Remove-Item2' { |
||||
|
BeforeAll { |
||||
|
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath '..\NTFSSecurity\bin\Release\NTFSSecurity.psd1' |
||||
|
Import-Module -Name $modulePath -Force -ErrorAction Stop |
||||
|
} |
||||
|
|
||||
|
AfterAll { |
||||
|
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue |
||||
|
} |
||||
|
|
||||
|
Context 'When called with -PassThur, the parameter name in 4.2.6 and earlier' { |
||||
|
BeforeAll { |
||||
|
$path = Join-Path -Path $TestDrive -ChildPath 'PassThur.txt' |
||||
|
Set-Content -LiteralPath $path -Value 'Remove-Item2 test' |
||||
|
|
||||
|
$removedItem = Remove-Item2 -Path $path -PassThur |
||||
|
} |
||||
|
|
||||
|
It 'Should delete the file' { |
||||
|
$path | Should -Not -Exist |
||||
|
} |
||||
|
|
||||
|
It 'Should return the deleted file, like -PassThru' { |
||||
|
$removedItem.Name | Should -BeExactly 'PassThur.txt' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue