Skip to content

Commit

Permalink
Merge pull request #10 from Fleid/rm_jsondiffpatch
Browse files Browse the repository at this point in the history
Integration tests check out
  • Loading branch information
Fleid authored Apr 7, 2020
2 parents e184390 + 36f0762 commit 0dfd159
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
41 changes: 30 additions & 11 deletions asa.unittest.tests/Get-AutRunResult.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Describe "Get-AutRunResult Nominal" {
Mock Get-AutFieldFromFileInfo {}
Mock Get-Content {return (@{FilePath="foobar"} | ConvertTo-Json)}
Mock Add-Content {}
Mock Invoke-External {}
Mock Compare-Object {}
Mock Out-File {}

It "tries to get a list of files" {
Expand All @@ -50,7 +50,7 @@ Describe "Get-AutRunResult Nominal" {
}

Mock Get-ChildItem {return 1}
It "calls Get-AutFieldFromFileInfo if find files" {
It "calls Get-AutFieldFromFileInfo if it find files" {
Get-AutRunResult `
-solutionPath $t_solutionPath `
-asaProjectName $t_asaProjectName `
Expand All @@ -75,8 +75,8 @@ Describe "Get-AutRunResult Nominal" {
-testID $t_testID `
-testCase $t_testCase | Out-Null

Assert-MockCalled Get-Content -Times 8 -Exactly -Scope It #4 for ref, 4 for output
Assert-MockCalled Add-Content -Times 8 -Exactly -Scope It #4 for ref, 4 for output
Assert-MockCalled Get-Content -Times 16 -Exactly -Scope It #4 for ref, 4 for output times 2
Assert-MockCalled Add-Content -Times 8 -Exactly -Scope It #4 for ref, 4 for output times 2
}

Mock Get-AutFieldFromFileInfo {return @(`
Expand All @@ -85,16 +85,35 @@ Describe "Get-AutRunResult Nominal" {
@{Basename0="001";FilePath="foobar2";Basename1="Output";Basename2="fb12"},`
@{Basename0="002";FilePath="foobar";Basename1="Output";Basename2="fb2"}`
)}
Mock Invoke-External {return $null}
It "Tests and generates N result files for N output files" {
Mock Compare-Object {return $null}
It "Tests and generates 0 result files for N correct tests" {
Get-AutRunResult `
-solutionPath $t_solutionPath `
-asaProjectName $t_asaProjectName `
-unittestFolder $t_unittestFolder `
-testID $t_testID `
-testCase $t_testCase | Out-Null

Assert-MockCalled Invoke-External -Times 4 -Exactly -Scope It
Assert-MockCalled Compare-Object -Times 4 -Exactly -Scope It
Assert-MockCalled Out-File -Times 0 -Exactly -Scope It
}

Mock Get-AutFieldFromFileInfo {return @(`
@{Basename0="003";FilePath="foobar";Basename1="Output";Basename2="fb3"},`
@{Basename0="001";FilePath="foobar1";Basename1="Output";Basename2="fb11"},`
@{Basename0="001";FilePath="foobar2";Basename1="Output";Basename2="fb12"},`
@{Basename0="002";FilePath="foobar";Basename1="Output";Basename2="fb2"}`
)}
Mock Compare-Object {return "ERROR"}
It "Tests and generates 4 result files for N correct tests" {
Get-AutRunResult `
-solutionPath $t_solutionPath `
-asaProjectName $t_asaProjectName `
-unittestFolder $t_unittestFolder `
-testID $t_testID `
-testCase $t_testCase | Out-Null

Assert-MockCalled Compare-Object -Times 4 -Exactly -Scope It
Assert-MockCalled Out-File -Times 4 -Exactly -Scope It
}

Expand All @@ -105,7 +124,7 @@ Describe "Get-AutRunResult Nominal" {
@{Basename0="001";FilePath="foobar3";Basename1="Output";Basename2="fb13"},`
@{Basename0="002";FilePath="foobar";Basename1="Output";Basename2="fb2"}`
)}
Mock Invoke-External {return "a"}
Mock Compare-Object {return "a"}
It "returns N for N errors" {
Get-AutRunResult `
-solutionPath $t_solutionPath `
Expand All @@ -132,7 +151,7 @@ Describe "Get-AutRunResult empty folders" {
Mock Get-AutFieldFromFileInfo {}
Mock Get-Content {}
Mock Add-Content {}
Mock Invoke-External {}
Mock Compare-Object {}
Mock Out-File {}

It "provides 0 error in output pipeline on an empty folder" {
Expand Down Expand Up @@ -173,7 +192,7 @@ Describe "Get-AutRunResult parameters" {
Mock Get-AutFieldFromFileInfo {}
Mock Get-Content {return (@{FilePath="foobar"} | ConvertTo-Json)}
Mock Add-Content {}
Mock Invoke-External {}
Mock Compare-Object {}
Mock Out-File {}

It "runs with a valid set of parameters" {
Expand Down Expand Up @@ -253,7 +272,7 @@ Describe "Get-AutRunResult paths" {
Mock Get-AutFieldFromFileInfo {}
Mock Get-Content {return (@{FilePath="foobar"} | ConvertTo-Json)}
Mock Add-Content {}
Mock Invoke-External {}
Mock Compare-Object {}
Mock Out-File {}

Mock Test-Path {return $true}
Expand Down
2 changes: 0 additions & 2 deletions asa.unittest.tests/New-AutProject.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ Describe "New-AutProject behavior dependencies" {
New-AutProject -installPath $t_installPath |
Assert-MockCalled Install-AutToolset -Times 1 -Exactly -Scope It -ParameterFilter {
($installPath -eq "$t_installPath\2_act") `
-and `
($npmpackages -eq "jsondiffpatch") `
-and `
($nugetpackages -eq "Microsoft.Azure.StreamAnalytics.CICD")
}
Expand Down
2 changes: 1 addition & 1 deletion asa.unittest/Public/New-AutProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Function New-AutProject{
if (-not (Test-Path "$installPath\3_assert")) {New-Item -ItemType Directory -Path "$installPath\3_assert" | Out-Null}

# Install dependencies
Install-AutToolset -installPath "$installPath\2_act" -npmpackages jsondiffpatch -nugetpackages Microsoft.Azure.StreamAnalytics.CICD
Install-AutToolset -installPath "$installPath\2_act" -nugetpackages Microsoft.Azure.StreamAnalytics.CICD

$gitIgnoreContent = `
"
Expand Down
7 changes: 0 additions & 7 deletions asa.unittest/Public/Start-AutRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ Function Start-AutRun{
# Final result
if ($errorCounter -gt 0) {
Write-Verbose "Ending Test Run with $errorCounter errors"
ForEach ($testCase in $testCases) {
$result = Get-Content "$solutionPath\$unittestFolder\3_assert\$testID\$testCase\*.Result.txt"
if ($result.Trim()) {
Write-Verbose $testCase
Write-Verbose "$result"
}
}
throw("Ending Test Run with $errorCounter errors")
}

Expand Down
Binary file modified asa.unittest/asa.unittest.psd1
Binary file not shown.
17 changes: 12 additions & 5 deletions asa.unittest/private/Get-AutRunResult.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Function Get-AutRunResult{
TestCase,
@{Name = "rawContent"; Expression = {"$testPath\$($_.SourceName).json"}}, #sa.exe output
@{Name = "testableFilePath"; Expression = {"$testPath\$($_.SourceName).testable.json"}}, #to be generated
@{Name = "sortedTestCaseOutputFilePath"; Expression = {"$testPath\$($_.Basename).sorted.json"}}, #to be generated
@{Name = "testCaseOutputFile"; Expression = {"$testPath\$asaProjectName\Inputs\$($_.FullName)"}} |
Foreach-Object -process {

Expand All @@ -81,8 +82,7 @@ Function Get-AutRunResult{

$referenceSortedContent = $referenceContent | Sort-Object -Property $referenceContentProperties | ConvertTo-JSON

$sortedTestCaseOutputFile = "$($_.testCaseOutputFile).sorted.json"
Add-Content -Path $sortedTestCaseOutputFile -Value $referenceSortedContent
Add-Content -Path $_.sortedTestCaseOutputFilePath -Value $referenceSortedContent

# Prepare output content (format, sorting)
$testableContent = ("[$(Get-Content -Path $_.rawContent)]") | ConvertFrom-Json
Expand All @@ -98,9 +98,16 @@ Function Get-AutRunResult{
Add-Content -Path $_.testableFilePath -Value $testableSortedContent

# Actual testing
$testResult = Invoke-External -l "jsondiffpatch" $sortedTestCaseOutputFile $_.testableFilePath;
$testResult | Out-File "$testPath\$($_.SourceName).Result.txt"
if ($testResult) {$errorCounter++}
$left = Get-Content $_.sortedTestCaseOutputFilePath
$right = Get-Content $_.testableFilePath
$testResult = Compare-Object $left $right

if ($testResult) {
$testResult | Out-File "$testPath\$($_.SourceName).Result.txt"
Write-Verbose ">> Errors on test $($_.TestCase)\$($_.SourceName):"
$testResult | Foreach-Object {Write-Verbose "$($_.SideIndicator) $($_.InputObject)"}
$errorCounter++
}
}

$errorCounter
Expand Down

0 comments on commit 0dfd159

Please sign in to comment.