tests/BykaDrBackup.Import.Tests.ps1
|
# Import smoke + parameter-validator tests for the BykaDrBackup module. BeforeAll { $script:ManifestPath = Join-Path $PSScriptRoot '..' 'BykaDrBackup.psd1' Import-Module $script:ManifestPath -Force } AfterAll { Remove-Module BykaDrBackup -ErrorAction SilentlyContinue } Describe 'BykaDrBackup import' { It 'imports without errors' { Get-Module BykaDrBackup | Should -Not -BeNullOrEmpty } It 'exposes Invoke-BykaDrBackup as a function' { Get-Command Invoke-BykaDrBackup -Module BykaDrBackup -ErrorAction Stop | Should -Not -BeNullOrEmpty } It 'does NOT export Private helpers (Backup-Item)' { # The manifest's FunctionsToExport restricts visibility from outside # the module, even though the loader dot-sources Private/Backup-Item.ps1. Get-Command Backup-Item -Module BykaDrBackup -ErrorAction SilentlyContinue | Should -BeNullOrEmpty } It 'exported function names match manifest FunctionsToExport pin' { # [G4] devops F6: assert against the explicit manifest list rather than # a raw count, so adding a new public function requires updating BOTH # the .psd1 AND this test together (intentional broadening), instead of # silently failing on count mismatch when a third function is added. $manifestPath = Join-Path $PSScriptRoot '..' 'BykaDrBackup.psd1' $m = Test-ModuleManifest -Path $manifestPath $exportedNames = (Get-Command -Module BykaDrBackup).Name | Sort-Object $manifestNames = $m.ExportedFunctions.Keys | Sort-Object $exportedNames | Should -Be $manifestNames } } Describe 'Invoke-BykaDrBackup parameter validation' { It 'rejects empty -Destination' { # ValidateNotNullOrEmpty kicks in before the body runs. { Invoke-BykaDrBackup -Destination '' } | Should -Throw } It 'rejects -KeepDays = 0 (range 1-365)' { { Invoke-BykaDrBackup -KeepDays 0 } | Should -Throw } It 'rejects -KeepDays = 366 (range 1-365)' { { Invoke-BykaDrBackup -KeepDays 366 } | Should -Throw } It 'rejects empty -ProjectRoot' { { Invoke-BykaDrBackup -ProjectRoot '' } | Should -Throw } } |