diff --git a/AU/Public/Update-Package.ps1 b/AU/Public/Update-Package.ps1 index 2f8bac7a..9f7f7980 100644 --- a/AU/Public/Update-Package.ps1 +++ b/AU/Public/Update-Package.ps1 @@ -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 ) @@ -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 } diff --git a/tests/Update-Package.Tests.ps1 b/tests/Update-Package.Tests.ps1 index dab28e77..44c7c278 100644 --- a/tests/Update-Package.Tests.ps1 +++ b/tests/Update-Package.Tests.ps1 @@ -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' {