Skip to content

Commit

Permalink
Merge pull request majkinetor#100 from Thilas/streams-fix-latest
Browse files Browse the repository at this point in the history
Fix issue with streams when using global variable Latest from au_GetLatest
  • Loading branch information
majkinetor authored Oct 29, 2017
2 parents 40cbcc5 + 154483b commit 8b1058c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,13 @@ function Update-Package {
}

function set_latest( [HashTable]$latest, [string] $version, $stream ) {
if (!$latest.PackageName) { $latest.PackageName = $package.Name }
if (!$latest.NuspecVersion) { $latest.NuspecVersion = $version }
if ($stream -and !$latest.Stream) { $latest.Stream = $stream }
$package.NuspecVersion = $latest.NuspecVersion
$global:Latest = $latest

$global:Latest = $global:au_Latest
$latest.Keys | % { $global:Latest.Remove($_) }
$global:Latest += $latest
}

function update_files( [switch]$SkipNuspecFile )
Expand Down Expand Up @@ -370,11 +372,14 @@ function Update-Package {
$package = [AUPackage]::new( $pwd )
if ($Result) { sv -Scope Global -Name $Result -Value $package }

$global:Latest = @{PackageName = $package.Name}

[System.Net.ServicePointManager]::SecurityProtocol = 'Ssl3,Tls,Tls11,Tls12' #https://github.com/chocolatey/chocolatey-coreteampackages/issues/366
$module = $MyInvocation.MyCommand.ScriptBlock.Module
"{0} - checking updates using {1} version {2}" -f $package.Name, $module.Name, $module.Version | result
try {
$res = au_GetLatest | select -Last 1
$global:au_Latest = $global:Latest
if ($res -eq $null) { throw 'au_GetLatest returned nothing' }

if ($res -eq 'ignore') { return $res }
Expand Down
27 changes: 27 additions & 0 deletions tests/Update-Package.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,33 @@ Describe 'Update-Package' -Tag update {
function global:au_GetLatest { throw 'test' }
{ update } | Should Throw "test"
}

It 'checks values in $Latest when entering au_GetLatest' {
function global:au_GetLatest {
$Latest.Count | Should Be 1
$Latest.PackageName | Should Be 'test_package'
@{ Version = '1.2' }
}
update
}

It 'supports returning custom values' {
function global:au_GetLatest { @{ Version = '1.2'; NewValue = 1 } }
update
$global:Latest.NewValue | Should Be 1
}

It 'supports adding values to $global:Latest' {
function global:au_GetLatest { $global:Latest += @{ NewValue = 1 }; @{ Version = '1.2' } }
update
$global:Latest.NewValue | Should Be 1
}

It 'supports adding values to $Latest' {
function global:au_GetLatest { $Latest.NewValue = 1; @{ Version = '1.2' } }
update
$global:Latest.NewValue | Should Be 1
}
}

Context 'Before and after update' {
Expand Down

0 comments on commit 8b1058c

Please sign in to comment.