Skip to content

Commit

Permalink
Rename Include to IncludeStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Démoulins committed Nov 9, 2017
1 parent 25ad3a4 commit 61bb507
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Update-Package {

#Streams to process, either a string or an array. If ommitted, all streams are processed.
#Single stream required when Force is specified.
$Include,
$IncludeStream,

#Force package update even if no new version is found.
#For multi streams packages, most recent stream is checked by default when Force is specified.
Expand Down Expand Up @@ -395,7 +395,7 @@ function Update-Package {

if ($global:au_Force) {
$Force = $true
if ($global:au_Include) { $Include = $global:au_Include }
if ($global:au_IncludeStream) { $IncludeStream = $global:au_IncludeStream }
}
} catch {
throw "au_GetLatest failed`n$_"
Expand All @@ -412,23 +412,23 @@ function Update-Package {
# In case of HashTable (i.e. not sorted), let's sort streams alphabetically descending
if ($res.Streams -is [HashTable]) { $streams = $streams | sort -Descending }

if ($Include) {
if ($Include -isnot [string] -and $Include -isnot [double] -and $Include -isnot [Array]) {
throw "`$Include must be either a String, a Double or an Array but is $($Include.GetType())"
if ($IncludeStream) {
if ($IncludeStream -isnot [string] -and $IncludeStream -isnot [double] -and $IncludeStream -isnot [Array]) {
throw "`$IncludeStream must be either a String, a Double or an Array but is $($IncludeStream.GetType())"
}
if ($Include -is [double]) { $Include = $Include -as [string] }
if ($Include -is [string]) {
if ($IncludeStream -is [double]) { $IncludeStream = $IncludeStream -as [string] }
if ($IncludeStream -is [string]) {
# Forcing type in order to handle case when only one version is included
[Array] $Include = $Include -split ',' | % { $_.Trim() }
[Array] $IncludeStream = $IncludeStream -split ',' | % { $_.Trim() }
}
} elseif ($Force) {
# When forcing update, a single stream is expected
# By default, we take the first one (i.e. the most recent one)
$Include = @($streams | select -First 1)
$IncludeStream = @($streams | select -First 1)
}
if ($Force -and (!$Include -or $Include.Length -ne 1)) { throw 'A single stream must be included when forcing package update' }
if ($Force -and (!$IncludeStream -or $IncludeStream.Length -ne 1)) { throw 'A single stream must be included when forcing package update' }

if ($Include) { $streams = $streams | ? { $_ -in $Include } }
if ($IncludeStream) { $streams = $streams | ? { $_ -in $IncludeStream } }
# Let's reverse the order in order to process streams starting with the oldest one
[Array]::Reverse($streams)

Expand Down
20 changes: 10 additions & 10 deletions tests/Update-Package.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Describe 'Update-Package using streams' -Tag updatestreams {

$global:au_Timeout = 100
$global:au_Force = $false
$global:au_Include = ''
$global:au_IncludeStream = ''
$global:au_NoHostOutput = $true
$global:au_NoCheckUrl = $true
$global:au_NoCheckChocoVersion = $true
Expand Down Expand Up @@ -129,7 +129,7 @@ Describe 'Update-Package using streams' -Tag updatestreams {
It 'can let user override the version of a specific stream' {
get_latest -Version 1.2.3
$global:au_Force = $true
$global:au_Include = '1.2'
$global:au_IncludeStream = '1.2'
$global:au_Version = '1.0'

$res = update -ChecksumFor 32 6> $null
Expand All @@ -152,7 +152,7 @@ Describe 'Update-Package using streams' -Tag updatestreams {
}

It 'automatically calculates the checksum' {
update -ChecksumFor 32 -Include 1.2 6> $null
update -ChecksumFor 32 -IncludeStream 1.2 6> $null

$global:Latest.Checksum32 | Should Not BeNullOrEmpty
$global:Latest.ChecksumType32 | Should Be 'sha256'
Expand Down Expand Up @@ -206,13 +206,13 @@ Describe 'Update-Package using streams' -Tag updatestreams {

It "throws an error when forcing update whithout specifying a stream" {
get_latest -Version 1.2.3
{ update -Force -Include 1.2,1.4 } | Should Throw 'A single stream must be included when forcing package update'
{ update -Force -IncludeStream 1.2,1.4 } | Should Throw 'A single stream must be included when forcing package update'
}

It "updates the package when forced using choco fix notation" {
get_latest -Version 1.2.3

$res = update -Force -Include 1.2
$res = update -Force -IncludeStream 1.2

$d = (get-date).ToString('yyyyMMdd')
$res.Updated | Should Be $true
Expand All @@ -225,7 +225,7 @@ Describe 'Update-Package using streams' -Tag updatestreams {
}

It "does not use choco fix notation if the package remote version is higher" {
$res = update -Force -Include 1.2
$res = update -Force -IncludeStream 1.2

$res.Updated | Should Be $true
$res.Streams.'1.2'.RemoteVersion | Should Be 1.2.4
Expand Down Expand Up @@ -270,7 +270,7 @@ Describe 'Update-Package using streams' -Tag updatestreams {
$streams.'1.2' = '{{PackageVersion}}'
$streams | ConvertTo-Json | Set-Content "$TestDrive\test_package_with_streams\test_package_with_streams.json" -Encoding UTF8

update -Include 1.2 *> $null
update -IncludeStream 1.2 *> $null

$global:Latest.NuspecVersion | Should Be '0.0'
}
Expand Down Expand Up @@ -329,20 +329,20 @@ Describe 'Update-Package using streams' -Tag updatestreams {
Context 'Before and after update' {
It 'calls au_BeforeUpdate if package is updated' {
function au_BeforeUpdate { $global:Latest.test = 1 }
update -Include 1.2
update -IncludeStream 1.2
$global:Latest.test | Should Be 1
}

It 'calls au_AfterUpdate if package is updated' {
function au_AfterUpdate { $global:Latest.test = 1 }
update -Include 1.2
update -IncludeStream 1.2
$global:Latest.test | Should Be 1
}

It 'doesnt call au_BeforeUpdate if package is not updated' {
get_latest -Version 1.2.3
function au_BeforeUpdate { $global:Latest.test = 1 }
update -Include 1.2
update -IncludeStream 1.2
$global:Latest.test | Should BeNullOrEmpty
}

Expand Down

0 comments on commit 61bb507

Please sign in to comment.