Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Honor -ErrorAction in Set-DockerImageVariantsVersions #100

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Describe "Set-DockerImageVariantsVersions" {
Context 'Parameters' {

It "Errors when -Versions is null" {
Mock Set-Content {}

{
Set-DockerImageVariantsVersions -Versions $null 6>$null
} | Should -Throw
Expand All @@ -30,6 +28,26 @@ Describe "Set-DockerImageVariantsVersions" {
Remove-Item "TestDrive:\generate" -Recurse -Force
}

It "Honors -ErrorAction Continue" {
Mock ConvertTo-Json {
throw
}

Set-DockerImageVariantsVersions '0.1.0' -ErrorAction Continue -ErrorVariable err 2>$null 6>$null

$err | Should -Not -Be $null
}

It "Honors -ErrorAction Stop" {
Mock ConvertTo-Json {
throw
}

{
Set-DockerImageVariantsVersions '0.1.0' -ErrorAction Stop 6>$null
} | Should -Throw
}

It "Sets version.json" {
Set-DockerImageVariantsVersions '0.1.0' 6>$null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@ function Set-DockerImageVariantsVersions {
)

process {
if ($InputObject) {
$Versions = $InputObject
}
$callerEA = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
try {
if ($InputObject) {
$Versions = $InputObject
}

$VERSIONS_JSON_FILE = "./generate/definitions/versions.json"
$content = ConvertTo-Json $Versions -Depth 100
if ($DoubleNewlines) {
$content = ($content -replace "`n", "`n`n").Trim()
$VERSIONS_JSON_FILE = "./generate/definitions/versions.json"
$content = ConvertTo-Json $Versions -Depth 100
if ($DoubleNewlines) {
$content = ($content -replace "`n", "`n`n").Trim()
}
"Writing $VERSIONS_JSON_FILE" | Write-Host -ForegroundColor Green
$content | Set-Content $VERSIONS_JSON_FILE -Encoding utf8
}catch {
if ($callerEA -eq 'Stop') {
throw
}
if ($callerEA -eq 'Continue') {
$_ | Write-Error -ErrorAction Continue
}
}
"Writing $VERSIONS_JSON_FILE" | Write-Host -ForegroundColor Green
$content | Set-Content $VERSIONS_JSON_FILE -Encoding utf8
}
}