Skip to content

Commit

Permalink
Add tests on report plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Démoulins committed Jan 2, 2019
1 parent 77d3bf2 commit 6746f8a
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 5 deletions.
98 changes: 98 additions & 0 deletions tests/Update-AUPackages.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,104 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
}

Context 'Plugins' {
It 'should execute text Report plugin' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1

$Options.Report = @{
Type = 'text'
Path = "$global:au_Root\report.txt"
}

$res = updateall -NoPlugins:$false -Options $Options 6> $null

$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_with_streams_1 +True +1\.3\.2 +1\.3\.1\b[\S\s]*'
$pattern += "\btest_package_with_streams_2 +False +1\.4-beta1 +1\.4-beta1\b[\S\s]*"
$pattern += '\btest_package_with_streams_1\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.4\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.2\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
$pattern += '\btest_package_with_streams_2\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute markdown Report plugin' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1

$Options.Report = @{
Type = 'markdown'
Path = "$global:au_Root\report.md"
Params = @{ Github_UserRepo = 'majkinetor/chocolatey' }
}

$res = updateall -NoPlugins:$false -Options $Options 6> $null

$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_with_streams_1\b.*\bTrue\b.*\bFalse\b.*\b1\.3\.2\b.*\b1\.3\.1\b[\S\s]*'
$pattern += "\btest_package_with_streams_2\b.*\bFalse\b.*\bFalse\b.*\b1\.4-beta1\b.*\b1\.4-beta1\b[\S\s]*"
$pattern += '\btest_package_with_streams_1\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.4\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.2\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
$pattern += '\btest_package_with_streams_2\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute GitReleases plugin when there are updates' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
Expand Down
64 changes: 59 additions & 5 deletions tests/Update-AUPackages.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,45 @@ Describe 'Update-AUPackages' -Tag updateall {
(gc $TestDrive\tmp_test).Count | Should be 3
}

It 'should execute Report plugin' {
It 'should execute text Report plugin' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1

$Options.Report = @{
Type = 'text'
Path = "$global:au_Root\report.txt"
}

$res = updateall -NoPlugins:$false -Options $Options 6> $null

$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_1 +True +1\.3 +1\.2\.3\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i +False +1\.2\.3 +1\.2\.3\b[\S\s]*"
}
$pattern += '\btest_package_1\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.3\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i\b[\S\s]*"
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
}
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute markdown Report plugin' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1

$Options.Report = @{
Type = 'markdown'
Path = "$global:au_Root\report.md"
Expand All @@ -113,10 +151,26 @@ Describe 'Update-AUPackages' -Tag updateall {

$res = updateall -NoPlugins:$false -Options $Options 6> $null

Test-Path $Options.Report.Path | Should Be $true

$report = gc $Options.Report.Path
($report -match "test_package_[1-3]").Count | Should Be 9
$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_1\b.*\bTrue\b.*\bFalse\b.*\b1\.3\b.*\b1\.2\.3\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i\b.*\bFalse\b.*\bFalse\b.*\b1\.2\.3\b.*\b1\.2\.3\b[\S\s]*"
}
$pattern += '\btest_package_1\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.3\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i\b[\S\s]*"
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
}
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute RunInfo plugin' {
Expand Down

0 comments on commit 6746f8a

Please sign in to comment.