Skip to content

Commit

Permalink
(chocolateyGH-442) always pass cache-location to choco
Browse files Browse the repository at this point in the history
  • Loading branch information
mwallner committed Jan 31, 2021
1 parent c28b044 commit 2b07cf6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
11 changes: 11 additions & 0 deletions Boxstarter.Chocolatey/Chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ function chocolatey {

$argsWithoutBoxstarterSpecials = @()
$skipNextArg = $false
$containsCacheLocation = $false

foreach ($a in $args) {
if ($skipNextArg) {
$skipNextArg = $false;
continue;
}

if ($a -match "^--?cache(Location|-location)?$") {
$containsCacheLocation = $true
}

# if a 'pure Boxstarter' parameter has been specified,
# we need to remove it from the command line arguments that
# will be passed to Chocolatey, as only Boxstarter is able to handle it
Expand All @@ -172,6 +177,12 @@ function chocolatey {
$argsWithoutBoxstarterSpecials += $a
}

if (-not $containsCacheLocation) {
Write-BoxstarterMessage "passing '-cacheLocation=$($env:temp)' to Chocolatey" -Verbose
$argsWithoutBoxstarterSpecials += "-cacheLocation"
$argsWithoutBoxstarterSpecials += $env:temp
}

$args = $argsWithoutBoxstarterSpecials
$rebootCodes = Add-DefaultRebootCodes -Codes $rebootCodes
Write-BoxstarterMessage "RebootCodes: '$rebootCodes' ($($rebootCodes.Count) elements)" -Verbose
Expand Down
76 changes: 53 additions & 23 deletions tests/Chocolatey/Chocolatey.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,24 @@ Describe "Call-Chocolatey" {
}

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes thru command" {
$passedArgs[0] | Should Be "Install"
}
it "passes thru package" {
$passedArgs[1] | Should Be "pkg"
}
it "injects cacheLocation" {
$passedArgs[2] | Should Be "-cacheLocation"
$passedArgs[3] | Should Be $env:temp
}
it "passes configed source" {
$passedArgs[2] | Should Be "-source"
$passedArgs[3] | Should Be "$($Boxstarter.LocalRepo);blah"
$passedArgs[4] | Should Be "-source"
$passedArgs[5] | Should Be "$($Boxstarter.LocalRepo);blah"
}
it "passes confirm" {
$passedArgs[4] | Should Be "-y"
$passedArgs[6] | Should Be "-y"
}
}

Expand All @@ -279,16 +283,20 @@ Describe "Call-Chocolatey" {
choco Uninstall pkg

it "passes expected params" {
$passedArgs.count | Should Be 3
$passedArgs.count | Should Be 5
}
it "passes thru command" {
$passedArgs[0] | Should Be "Uninstall"
}
it "passes thru package" {
$passedArgs[1] | Should Be "pkg"
}
it "injects cacheLocation" {
$passedArgs[2] | Should Be "-cacheLocation"
$passedArgs[3] | Should Be $env:temp
}
it "passes confirm" {
$passedArgs[2] | Should Be "-y"
$passedArgs[4] | Should Be "-y"
}
}

Expand All @@ -299,7 +307,7 @@ Describe "Call-Chocolatey" {
choco Install pkg --source blah --bing=boom

it "passes expected params" {
$passedArgs.count | Should Be 7
$passedArgs.count | Should Be 9
}
it "passes source" {
$passedArgs[2] | Should Be "--source"
Expand All @@ -309,6 +317,10 @@ Describe "Call-Chocolatey" {
$passedArgs[4] | Should Be "--bing"
$passedArgs[5] | Should Be "boom"
}
it "injects cacheLocation" {
$passedArgs[6] | Should Be "-cacheLocation"
$passedArgs[7] | Should Be $env:temp
}
}

context "when passing source as --source with =" {
Expand All @@ -318,12 +330,16 @@ Describe "Call-Chocolatey" {
choco Install pkg --source=blah

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes source" {
$passedArgs[2] | Should Be "--source"
$passedArgs[3] | Should Be "blah"
}
it "injects cacheLocation" {
$passedArgs[4] | Should Be "-cacheLocation"
$passedArgs[5] | Should Be $env:temp
}
}

context "when passing source as -source" {
Expand All @@ -333,12 +349,16 @@ Describe "Call-Chocolatey" {
choco Install pkg -source blah

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes source" {
$passedArgs[2] | Should Be "-source"
$passedArgs[3] | Should Be "blah"
}
it "injects cacheLocation" {
$passedArgs[4] | Should Be "-cacheLocation"
$passedArgs[5] | Should Be $env:temp
}
}

context "when passing source as -s" {
Expand All @@ -348,12 +368,16 @@ Describe "Call-Chocolatey" {
choco Install pkg -s blah

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes source" {
$passedArgs[2] | Should Be "-s"
$passedArgs[3] | Should Be "blah"
}
it "injects cacheLocation" {
$passedArgs[4] | Should Be "-cacheLocation"
$passedArgs[5] | Should Be $env:temp
}
}

context "when passing force as -force:`$true" {
Expand All @@ -363,9 +387,9 @@ Describe "Call-Chocolatey" {
choco Install pkg -force:$true

it "passes expected params" {
$passedArgs.count | Should Be 6
$passedArgs.count | Should Be 8
}
it "passes source" {
it "passes force" {
$passedArgs[2] | Should Be "-f"
}
}
Expand All @@ -377,9 +401,9 @@ Describe "Call-Chocolatey" {
choco Install pkg -force:$false

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes source" {
it "passes force (false)" {
$passedArgs -contains "-f" | Should Be $false
}
}
Expand All @@ -391,7 +415,7 @@ Describe "Call-Chocolatey" {
choco Install pkg -f

it "passes expected params" {
$passedArgs.count | Should Be 6
$passedArgs.count | Should Be 8
}
it "passes source" {
$passedArgs[2] | Should Be "-f"
Expand All @@ -405,7 +429,7 @@ Describe "Call-Chocolatey" {
choco Install pkg -force

it "passes expected params" {
$passedArgs.count | Should Be 6
$passedArgs.count | Should Be 8
}
it "passes source" {
$passedArgs[2] | Should Be "-force"
Expand All @@ -420,13 +444,15 @@ Describe "Call-Chocolatey" {
$global:VerbosePreference="SilentlyContinue"

it "passes expected params" {
$passedArgs.count | Should Be 6
$passedArgs.count | Should Be 8
$passedArgs[0] | Should Be "Install"
$passedArgs[1] | Should Be "pkg"
$passedArgs[2] | Should Be "-Source"
$passedArgs[2] | Should Be "-cacheLocation"
$passedArgs[3] | Should Be $env:temp
$passedArgs[4] | Should Be "-Source"
# $passedArgs[3] -> feeds, may differ from system to system
$passedArgs[4] | Should Be "-Verbose"
$passedArgs[5] | Should Be "-y"
$passedArgs[6] | Should Be "-Verbose"
$passedArgs[7] | Should Be "-y"
}
}

Expand All @@ -439,7 +465,7 @@ Describe "Call-Chocolatey" {
$passedArgs | Should Not BeNullOrEmpty

it "passes expected params" {
$passedArgs.count | Should Be 8 # actually 7 + 1 "-Verbose" is appended
$passedArgs.count | Should Be 10 # actually 9 + 1 "-Verbose" is appended
}
it "passes all parameters in correct order" {
$passedArgs[0] | Should Be "Install"
Expand All @@ -462,14 +488,16 @@ Describe "Call-Chocolatey" {
$passedArgs | Should Not BeNullOrEmpty

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes all parameters in correct order" {
$passedArgs[0] | Should Be "Install"
$passedArgs[1] | Should Be "pkg" # package will always be first argument (reordering happens!)
$passedArgs[2] | Should Be "-y" # passed -y is after package because of the reordering
$passedArgs[3] | Should Be "--source"
$passedArgs[4] | Should Be "blah"
$passedArgs[5] | Should Be "-cacheLocation"
$passedArgs[6] | Should Be $env:temp
}
}

Expand All @@ -482,14 +510,16 @@ Describe "Call-Chocolatey" {
$passedArgs | Should Not BeNullOrEmpty

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs.count | Should Be 7
}
it "passes all parameters in correct order" {
$passedArgs[0] | Should Be "Install"
$passedArgs[1] | Should Be "pkg" # package will always be first argument (reordering happens!)
$passedArgs[2] | Should Be "-y" # passed -y is after package because of the reordering
$passedArgs[3] | Should Be "--source"
$passedArgs[4] | Should Be "blah"
$passedArgs[5] | Should Be "-cacheLocation"
$passedArgs[6] | Should Be $env:temp
}
}

Expand Down

0 comments on commit 2b07cf6

Please sign in to comment.