Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Fix issue with streams when using global variable Latest from au_GetLatest #100

Merged
merged 1 commit into from
Oct 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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