-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added integration tests for PSCodeHealth report object
- Loading branch information
1 parent
3289ebd
commit ac3591d
Showing
41 changed files
with
600 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
$ModuleName = 'PSCodeHealth' | ||
Import-Module "$PSScriptRoot\..\..\$ModuleName\$($ModuleName).psd1" -Force | ||
$CodePath = "$PSScriptRoot\..\TestData\coveralls" | ||
|
||
Describe 'Invoke-PSCodeHealth' { | ||
|
||
$Result = Invoke-PSCodeHealth -Path $CodePath | ||
$ExpectedFunctionNames = @('Add-CoverageInfo','Merge-CoverageResult','Get-CoverageArray','Format-FileCoverage','Get-CommandsForFile','Get-GitInfo','Format-Coverage','Publish-Coverage','Get-CoveragePercentage') | ||
$AddCoverageInfo = $Result.FunctionHealthRecords | Where-Object FunctionName -eq 'Add-CoverageInfo' | ||
$GetCoverageArray = $Result.FunctionHealthRecords | Where-Object FunctionName -eq 'Get-CoverageArray' | ||
$FormatFileCoverage = $Result.FunctionHealthRecords | Where-Object FunctionName -eq 'Format-FileCoverage' | ||
$FormatCoverage = $Result.FunctionHealthRecords | Where-Object FunctionName -eq 'Format-Coverage' | ||
$GetCoveragePercentage = $Result.FunctionHealthRecords | Where-Object FunctionName -eq 'Get-CoveragePercentage' | ||
|
||
Context 'Given code in coveralls module, Invoke-PSCodeHealth return the expected FunctionHealthRecords' { | ||
|
||
It 'Should find 9 function definitions' { | ||
$Result.FunctionHealthRecords.Count | Should Be 9 | ||
} | ||
It 'Should return only functions with the expected function names' { | ||
Foreach ( $FunctionName in $Result.FunctionHealthRecords.FunctionName ) { | ||
$FunctionName | Should BeIn $ExpectedFunctionNames | ||
} | ||
} | ||
It 'Should return correct LinesOfCode metric for the function Add-CoverageInfo' { | ||
$AddCoverageInfo.LinesOfCode | Should Be 14 | ||
} | ||
It 'Should return correct ScriptAnalyzerFindings metric for the function Add-CoverageInfo' { | ||
$AddCoverageInfo.ScriptAnalyzerFindings | Should Be 0 | ||
} | ||
It 'Should return correct TestCoverage metric for the function Add-CoverageInfo' { | ||
$AddCoverageInfo.TestCoverage | Should Be 0 | ||
} | ||
It 'Should return correct Complexity metric for the function Add-CoverageInfo' { | ||
$AddCoverageInfo.Complexity | Should Be 1 | ||
} | ||
It 'Should return correct MaximumNestingDepth metric for the function Add-CoverageInfo' { | ||
$AddCoverageInfo.MaximumNestingDepth | Should Be 1 | ||
} | ||
It 'Should return correct LinesOfCode metric for the function Get-CoverageArray' { | ||
$GetCoverageArray.LinesOfCode | Should Be 30 | ||
} | ||
It 'Should return correct ScriptAnalyzerFindings metric for the function Get-CoverageArray' { | ||
$GetCoverageArray.ScriptAnalyzerFindings | Should Be 0 | ||
} | ||
It 'Should return correct TestCoverage metric for the function Get-CoverageArray' { | ||
$GetCoverageArray.TestCoverage | Should Be 0 | ||
} | ||
It 'Should return correct Complexity metric for the function Get-CoverageArray' { | ||
$GetCoverageArray.Complexity | Should Be 5 | ||
} | ||
It 'Should return correct MaximumNestingDepth metric for the function Get-CoverageArray' { | ||
$GetCoverageArray.MaximumNestingDepth | Should Be 3 | ||
} | ||
It 'Should return correct LinesOfCode metric for the function Format-FileCoverage' { | ||
$FormatFileCoverage.LinesOfCode | Should Be 24 | ||
} | ||
It 'Should return correct ScriptAnalyzerFindings metric for the function Format-FileCoverage' { | ||
$FormatFileCoverage.ScriptAnalyzerFindings | Should Be 0 | ||
} | ||
It 'Should return correct TestCoverage metric for the function Format-FileCoverage' { | ||
$FormatFileCoverage.TestCoverage | Should Be 100 | ||
} | ||
It 'Should return correct Complexity metric for the function Format-FileCoverage' { | ||
$FormatFileCoverage.Complexity | Should Be 2 | ||
} | ||
It 'Should return correct MaximumNestingDepth metric for the function Format-FileCoverage' { | ||
$FormatFileCoverage.MaximumNestingDepth | Should Be 1 | ||
} | ||
It 'Should return correct LinesOfCode metric for the function Format-Coverage' { | ||
$FormatCoverage.LinesOfCode | Should Be 39 | ||
} | ||
It 'Should return correct ScriptAnalyzerFindings metric for the function Format-Coverage' { | ||
$FormatCoverage.ScriptAnalyzerFindings | Should Be 0 | ||
} | ||
It 'Should return correct TestCoverage metric for the function Format-Coverage' { | ||
$FormatCoverage.TestCoverage | Should Be 0 | ||
} | ||
It 'Should return correct Complexity metric for the function Format-Coverage' { | ||
$FormatCoverage.Complexity | Should Be 3 | ||
} | ||
It 'Should return correct MaximumNestingDepth metric for the function Format-Coverage' { | ||
$FormatCoverage.MaximumNestingDepth | Should Be 1 | ||
} | ||
It 'Should return correct LinesOfCode metric for the function Get-CoveragePercentage' { | ||
$GetCoveragePercentage.LinesOfCode | Should Be 16 | ||
} | ||
It 'Should return correct ScriptAnalyzerFindings metric for the function Get-CoveragePercentage' { | ||
$GetCoveragePercentage.ScriptAnalyzerFindings | Should Be 0 | ||
} | ||
It 'Should return correct TestCoverage metric for the function Get-CoveragePercentage' { | ||
$GetCoveragePercentage.TestCoverage | Should Be 100 | ||
} | ||
It 'Should return correct Complexity metric for the function Get-CoveragePercentage' { | ||
$GetCoveragePercentage.Complexity | Should Be 2 | ||
} | ||
It 'Should return correct MaximumNestingDepth metric for the function Get-CoveragePercentage' { | ||
$GetCoveragePercentage.MaximumNestingDepth | Should Be 1 | ||
} | ||
It 'The health report should have the expected Files property' { | ||
$Result.Files | Should Be 3 | ||
} | ||
It 'The health report should have the expected Functions property' { | ||
$Result.Functions | Should Be 9 | ||
} | ||
It 'The health report should have the expected LinesOfCodeTotal property' { | ||
$Result.LinesOfCodeTotal | Should Be 201 | ||
} | ||
It 'The health report should have the expected LinesOfCodeAverage property' { | ||
$Result.LinesOfCodeAverage | Should Be 22.33 | ||
} | ||
It 'The health report should have the expected LinesOfCodeAverage property' { | ||
$Result.LinesOfCodeAverage | Should Be 22.33 | ||
} | ||
It 'The health report should have the expected ScriptAnalyzerFindingsTotal property' { | ||
$Result.ScriptAnalyzerFindingsTotal | Should Be 0 | ||
} | ||
It 'The health report should have the expected NumberOfTests property' { | ||
$Result.NumberOfTests | Should Be 10 | ||
} | ||
It 'The health report should have the expected NumberOfFailedTests property' { | ||
$Result.NumberOfFailedTests | Should Be 0 | ||
} | ||
It 'The health report should have the expected NumberOfPassedTests property' { | ||
$Result.NumberOfPassedTests | Should Be 10 | ||
} | ||
It 'The health report should have the expected TestsPassRate property' { | ||
$Result.TestsPassRate | Should Be 100 | ||
} | ||
It 'The health report should have the expected TestCoverage property' { | ||
$Result.TestCoverage | Should Be 21.43 | ||
} | ||
It 'The health report should have the expected CommandsMissedTotal property' { | ||
$Result.CommandsMissedTotal | Should Be 77 | ||
} | ||
It 'The health report should have the expected ComplexityAverage property' { | ||
$Result.ComplexityAverage | Should Be 2 | ||
} | ||
It 'The health report should have the expected NestingDepthAverage property' { | ||
$Result.NestingDepthAverage | Should Be 1.11 | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Describe 'Fake tests' { | ||
|
||
Context 'Fake test case' { | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") | ||
. "$here\$sut" | ||
|
||
Describe "Get-CoveragePercentage" { | ||
Context "Providing a correct return" { | ||
BeforeAll { | ||
$content = "{""created_at"":""2017-03-16T12:37:17Z"",""url"":null,""commit_message"":""Add fake data to CA_KEY when it's not present"",""branch"":""master"",""committer_name"":""Jan De Dobbeleer"",""committer_email"":""jan@gmail.com"",""commit_sha"":""ba5947862030d86208d0181189c160df04e5c309"",""repo_name"":""JanJoris/coveralls"",""badge_url"":""https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_13.svg"",""coverage_change"":0.0,""covered_percent"":%percentage%}" | ||
} | ||
It "has a coverage percentage of 13" { | ||
Mock Invoke-WebRequest { return @{ Content = $content.Replace('%percentage%', '13') }} | ||
Get-CoveragePercentage -RepositoryLink coveralls | Should Be 13 | ||
} | ||
It "has a coverage percentage of 28" { | ||
Mock Invoke-WebRequest { return @{ Content = $content.Replace('%percentage%', '28') }} | ||
Get-CoveragePercentage -RepositoryLink coveralls | Should Be 28 | ||
} | ||
} | ||
Context "Providing an exception return" { | ||
It "throws an error when providing bogus info" { | ||
{ Get-CoveragePercentage -RepositoryLink coveralls -ErrorAction Stop } | Should Throw | ||
} | ||
It "throws an error when providing a non-existing repository" { | ||
{ Get-CoveragePercentage -RepositoryLink https://coveralls.io/coveralls/coveralls -ErrorAction Stop } | Should Throw | ||
} | ||
} | ||
Context "Providing crappy data" { | ||
It "has no content object to parse" { | ||
Mock Invoke-WebRequest { return @{ NotContent = "I am so crappy" }} | ||
{ Get-CoveragePercentage -RepositoryLink coveralls -ErrorAction Stop } | Should Throw | ||
} | ||
} | ||
} | ||
|
||
Describe "Get-CommandsForFile" { | ||
Context "Receiving proper input" { | ||
It "has 2 commands that match the file" { | ||
$commands = @( | ||
@{ | ||
File = "file.ps1" | ||
Line = 1 | ||
}, | ||
@{ | ||
File = "file.ps1" | ||
Line = 2 | ||
}, | ||
@{ | ||
File = "file2.ps1" | ||
Line = 3 | ||
} | ||
) | ||
Mock Get-Item { return @{ FullName = 'file.ps1' }} | ||
$result = Get-CommandsForFile -Commands $commands -File 'file.ps1' | ||
$result.Count | Should be 2 | ||
} | ||
It "has 0 commands that match the file" { | ||
$commands = @( | ||
@{ | ||
File = "file2.ps1" | ||
Line = 1 | ||
}, | ||
@{ | ||
File = "file2.ps1" | ||
Line = 2 | ||
} | ||
) | ||
Mock Get-Item { return @{ FullName = 'file.ps1' }} | ||
$result = Get-CommandsForFile -Commands $commands -File 'file.ps1' | ||
$result.Count | Should be 0 | ||
} | ||
} | ||
Context "Receiving crappy input" { | ||
It "should not output any match" { | ||
$commands = @{ | ||
Balony = "garbage" | ||
Ohn0 = 1324343 | ||
} | ||
Mock Get-Item { return @{ FullName = 'file.ps1' }} | ||
$result = Get-CommandsForFile -Commands $commands -File 'file.ps1' | ||
$result.Count | Should be 0 | ||
} | ||
} | ||
} | ||
|
||
Describe "Format-FileCoverage" { | ||
Context "Receiving proper input" { | ||
It "outputs the expected information" { | ||
$expected = New-Object -TypeName PSObject -Property @{ | ||
name = 'file.ps1' | ||
source_digest = '123456789' | ||
coverage = 'Test' | ||
} | ||
Mock Get-FileHash { return @{ Hash = '123456789' }} | ||
Mock Get-Item -ParameterFilter { $Path -eq 'RootFolder' } { @{ FullName = 'root' } } | ||
Mock Get-Item -ParameterFilter { $Path -eq 'File' } { @{ FullName = 'root\file.ps1' } } | ||
$result = Format-FileCoverage -CoverageArray 'Test' -File 'File' -RootFolder 'RootFolder' | ||
$result | Should MatchExactly $expected | ||
} | ||
It "handles the paths without an issue" { | ||
$expected = New-Object -TypeName PSObject -Property @{ | ||
name = 'file.ps1' | ||
source_digest = '123456789' | ||
coverage = 'Test' | ||
} | ||
Mock Get-FileHash { return @{ Hash = '123456789' }} | ||
Mock Get-Item -ParameterFilter { $Path -eq 'RootFolder' } { @{ FullName = 'root' } } | ||
Mock Get-Item -ParameterFilter { $Path -eq 'File' } { @{ FullName = 'file.ps1' } } | ||
$result = Format-FileCoverage -CoverageArray 'Test' -File 'File' -RootFolder 'RootFolder' | ||
$result | Should MatchExactly $expected | ||
} | ||
} | ||
} |
Oops, something went wrong.