Skip to content

Commit

Permalink
Add Pester tests for streams on Update-AUPackages
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Démoulins authored and majkinetor committed Oct 29, 2017
1 parent be9d2b9 commit e60afae
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/Update-AUPackages.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ import-module $PSScriptRoot\..\AU
Describe 'Update-AUPackages' -Tag updateall {
$saved_pwd = $pwd

function global:nuspec_file() { [xml](gc $PSScriptRoot/test_package/test_package.nuspec) }
$pkg_no = 3
$pkg_no = 5

BeforeEach {
$stream_no = 0
$global:au_Root = "TestDrive:\packages"
$global:au_NoPlugins = $true

rm -Recurse $global:au_root -ea ignore
foreach ( $i in 1..$pkg_no ) {
$name = "test_package_$i"
$base = if ($i -le 3) {$stream_no++; 'test_package'} else {$stream_no += 3; 'test_package_with_streams'}
$name = "${base}_$i"
$path = "$au_root\$name"

cp -Recurse -Force $PSScriptRoot\test_package $path
$nu = nuspec_file
cp -Recurse -Force "$PSScriptRoot\$base" $path
$nu = [xml](gc "$PSScriptRoot\$base\$base.nuspec")
$nu.package.metadata.id = $name
rm "$au_root\$name\*.nuspec"
$nu.OuterXml | sc "$path\$name.nuspec"
if (Test-Path "$path\$base.json") { mv "$path\$base.json" "$path\$name.json" }

$module_path = Resolve-Path $PSScriptRoot\..\AU
"import-module '$module_path' -Force", (gc $path\update.ps1 -ea ignore) | sc $path\update.ps1
Expand Down Expand Up @@ -138,7 +140,7 @@ Describe 'Update-AUPackages' -Tag updateall {
}
}

It 'should update package with checsum verification mode' {
It 'should update package with checksum verification mode' {

$choco_path = gcm choco.exe | % Source
$choco_hash = Get-FileHash $choco_path -Algorithm SHA256 | % Hash
Expand Down Expand Up @@ -178,7 +180,7 @@ Describe 'Update-AUPackages' -Tag updateall {

lsau | measure | % Count | Should Be $pkg_no
$res.Count | Should Be $pkg_no
($res.Result -match 'No new version found').Count | Should Be $pkg_no
($res.Result -match 'No new version found').Count | Should Be $stream_no
($res | ? Updated).Count | Should Be 0
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1.2": "1.2.3",
"1.3": "1.3.1",
"1.4": "1.4-beta1"
}
23 changes: 23 additions & 0 deletions tests/test_package_with_streams/test_package_with_streams.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>test_package_with_streams</id>
<version>1.2.3</version>
<title>Test Package with Streams</title>
<authors>Miodrag Milić</authors>
<owners>Miodrag Milić</owners>
<licenseUrl>http://www.gnu.org/copyleft/gpl.html</licenseUrl>
<projectUrl>https://github.com/majkinetor/au</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is a test package with streams for Pester</description>
<summary>This is a test package with streams for Pester</summary>
<tags>test streams pester</tags>
<dependencies>
<dependency id="test.install" version="1.0" />
</dependencies>
<releaseNotes>None</releaseNotes>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
12 changes: 12 additions & 0 deletions tests/test_package_with_streams/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ErrorActionPreference = 'Stop'

$packageName = 'test_package_with_streams'
$url32 = gcm choco.exe | % Source
$checksum32 = ''

$params = @{
packageName = $packageName
fileFullPath = "$PSScriptRoot\choco.exe"
Url = "file:///$url32"
}
Get-ChocolateyWebFile @params
13 changes: 13 additions & 0 deletions tests/test_package_with_streams/update.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function global:au_SearchReplace() {
@{}
}

function global:au_GetLatest() {
@{ Streams = @{
'1.4' = @{ Version = '1.4-beta1' }
'1.2' = @{ Version = '1.2.3' }
'1.3' = @{ Version = '1.3.1' }
} }
}

update

0 comments on commit e60afae

Please sign in to comment.