Skip to content

Commit

Permalink
Test AzLogin
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Hannebauer committed Nov 7, 2024
1 parent 3196ef9 commit c6bc70a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SCEPman/Private/az-commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function AzLogin {
$accountInfo = Convert-LinesToObject($account)
} catch {
Write-Verbose "Raw output from az account show: $account"
Write-Error "Error parsing output from az account show:�n$_"
Write-Error "Error parsing output from az account show: $_"
throw $_
}
Write-Information "Logged in to az as $($accountInfo.user.name)"
Expand Down
16 changes: 16 additions & 0 deletions Tests/az-commands.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
BeforeAll {
. $PSScriptRoot/../SCEPman/Private/az-commands.ps1

. $PSScriptRoot/test-helpers.ps1
}

Describe 'az-commands' {
It 'Should find that this test does not run in Azure Cloud Shell' {
$isAzureCloudShell = IsAzureCloudShell
$isAzureCloudShell | Should -Be $false
}

Context 'AzLogin' {
It 'Should succeed if already logged in' {
# Arrange
mock az { return '{ "user": { "name": "testuser" } }' } -ParameterFilter { CheckAzParameters -argsFromCommand $args -azCommandPrefix 'account show' }
EnsureNoAdditionalAzCalls

# Act
$account = AzLogin

# Assert
$account.user.name | Should -Be "testuser"
}
}
}

0 comments on commit c6bc70a

Please sign in to comment.