82 lines
3.2 KiB
PowerShell
82 lines
3.2 KiB
PowerShell
|
BeforeAll {
|
||
|
$Repo = Get-RepoPath
|
||
|
Import-Module $Repo.Src.Manifest.Item.FullName -Force
|
||
|
$MoveBackup = @{
|
||
|
Path = $Repo.Build.FileLinterLogPath
|
||
|
Destination = Join-Path -Path $Repo.Build.Path -ChildPath 'FileLinter.backup'
|
||
|
}
|
||
|
Move-Item @MoveBackup
|
||
|
}
|
||
|
|
||
|
Describe 'Invoke-FileLinter' {
|
||
|
Context 'Default tests' -Tag 'Default' {
|
||
|
It 'Test Function' {
|
||
|
{ Get-Command -Name 'Invoke-FileLinter' -Module $Repo.Artifact } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Test Help' {
|
||
|
{ Get-Help -Name 'Invoke-FileLinter' } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Help Content' {
|
||
|
$foo = Get-Help -Name 'Invoke-FileLinter'
|
||
|
$foo.Synopsis.Length | Should -BeGreaterThan 5
|
||
|
$foo.Description.Count | Should -BeGreaterOrEqual 1
|
||
|
$foo.Description[0].Text.Length | Should -BeGreaterThan 5
|
||
|
}
|
||
|
}
|
||
|
Context 'Coding tests' -Tag 'Unit' {
|
||
|
# Mocking doesn't get executed. Switch to Integration test class to avoid duplicated output.
|
||
|
BeforeEach {
|
||
|
Mock 'Write-FailureStateFile' {
|
||
|
Write-Debug 'Mocking function Write-FailureStateFile.'
|
||
|
} -ModuleName 'DroneHelper'
|
||
|
|
||
|
Mock 'Write-ResultFile' {
|
||
|
Write-Debug 'Mocking function Write-ResultFile.'
|
||
|
} -ModuleName 'DroneHelper'
|
||
|
}
|
||
|
It 'Should throw' {
|
||
|
#Mock 'Write-FailureStateFile' { Write-Debug 'Mocking Report generator' }
|
||
|
#Mock 'Write-ResultFile' { Write-Debug 'Mocking function Write-ResultFile.' }
|
||
|
{ Invoke-FileLinter -foo } | Should -Throw
|
||
|
}
|
||
|
It 'Should not throw' {
|
||
|
#Mock 'Write-FailureStateFile' { Write-Debug 'Mocking Report generator' }
|
||
|
#Mock 'Write-ResultFile' { Write-Debug 'Mocking function Write-ResultFile.' }
|
||
|
{ Invoke-FileLinter } | Should -Not -Throw
|
||
|
}
|
||
|
|
||
|
It 'Should have found files' {
|
||
|
#Mock Write-FailureStateFile { Write-Debug 'Mocking Report generator' }
|
||
|
#Mock 'Write-ResultFile' { Write-Debug 'Mocking function Write-ResultFile.' }
|
||
|
$res = Invoke-FileLinter -PassThru
|
||
|
$res.FilesCount | Should -Not -BeNullOrEmpty
|
||
|
$res.FilesCount | Should -BeGreaterThan 0
|
||
|
}
|
||
|
|
||
|
It 'Should run without linter issues' {
|
||
|
#Mock 'Write-FailureStateFile' { Write-Debug 'Mocking Report generator' }
|
||
|
#Mock 'Write-ResultFile' { Write-Debug 'Mocking function Write-ResultFile.' }
|
||
|
$res = Invoke-FileLinter -PassThru
|
||
|
$res.FailedCount | Should -Be 0
|
||
|
}
|
||
|
|
||
|
It 'Should Sum up ' {
|
||
|
#Mock 'Write-FailureStateFile' { Write-Debug 'Mocking Report generator' }
|
||
|
#Mock 'Write-ResultFile' { Write-Debug 'Mocking function Write-ResultFile.' }
|
||
|
$res = Invoke-FileLinter -PassThru
|
||
|
$res.FailedCount | Should -Be 0
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
AfterAll {
|
||
|
$Repo = Get-RepoPath
|
||
|
$RestoreBackup = @{
|
||
|
Path = Join-Path -Path $Repo.Build.Path -ChildPath 'FileLinter.backup'
|
||
|
Destination = $Repo.Build.FileLinterLogPath
|
||
|
}
|
||
|
Move-Item @RestoreBackup -Force
|
||
|
}
|