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

Enabled live test and added new function for local debug #20656

Merged
merged 1 commit into from
Jan 13, 2023
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
14 changes: 10 additions & 4 deletions .azure-pipelines/live-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ parameters:
default: 7.0.x

variables:
LiveTestArtifactsName: LiveTestArtifacts
LiveTestDataLocation: $(Pipeline.Workspace)/$(LiveTestArtifactsName)
ArtifactsName: LiveTestArtifacts
DataLocation: $(Pipeline.Workspace)/$(ArtifactsName)
EnableTestCoverage: true
TestCoverageLocation: $(LiveTestDataLocation)
TestCoverageLocation: $(DataLocation)

schedules:
- cron: "0 19 * * *"
displayName: Daily Live Test
branches:
include:
- shared/livetest

pr: none
trigger: none

jobs:
- template: util/live-test-steps.yml
Expand Down
13 changes: 6 additions & 7 deletions .azure-pipelines/util/live-test-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ parameters:

jobs:
- job: ${{ parameters.name }}
timeoutInMinutes: 180
pool:
vmImage: ${{ parameters.vmImage }}

Expand All @@ -32,7 +31,7 @@ jobs:
pwsh: true
targetType: inline
script:
New-Item -Name $(LiveTestArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force
New-Item -Name $(ArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force

- task: DownloadPipelineArtifact@2
condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'), eq(variables['BuildPipelineBuildId'], ''))
Expand Down Expand Up @@ -65,7 +64,7 @@ jobs:
pwsh: true
targetType: inline
script: |
$azPackagesDir = New-Item -Name AzPackages -Path $(LiveTestDataLocation) -ItemType Directory -Force
$azPackagesDir = New-Item -Name AzPackages -Path $(DataLocation) -ItemType Directory -Force
$azPackagesFiles = Join-Path -Path $(Pipeline.Workspace) -ChildPath *.nupkg
Move-Item -Path $azPackagesFiles -Destination $azPackagesDir
Get-ChildItem -LiteralPath $azPackagesDir
Expand All @@ -76,7 +75,7 @@ jobs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InstallLiveTestAzModules.ps1 -Source $(GalleryName) -AzPackagesLocation (Convert-Path -LiteralPath $(LiveTestDataLocation) | Join-Path -ChildPath AzPackages)'
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InstallLiveTestAzModules.ps1 -Source $(GalleryName) -AzPackagesLocation (Convert-Path -LiteralPath $(DataLocation) | Join-Path -ChildPath AzPackages)'

- task: PowerShell@2
displayName: Connect Azure with live test service principal
Expand All @@ -92,7 +91,7 @@ jobs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 $(Build.BuildId) ${{ parameters.vmImage }} ${{ parameters.psVersion }} $(Build.SourcesDirectory) $(LiveTestDataLocation)'
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 -BuildId $(Build.BuildId) -OSVersion ${{ parameters.vmImage }} -PSVersion ${{ parameters.psVersion }} -RepoLocation $(Build.SourcesDirectory)'
failOnStderr: true

- task: PowerShell@2
Expand All @@ -101,11 +100,11 @@ jobs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/SaveLiveTestResult.ps1
arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(TestCoverageTableName) $(LiveTestDataLocation)
arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(TestCoverageTableName) $(DataLocation)

- task: PublishPipelineArtifact@1
displayName: Publish live test results to pipeline artifact
inputs:
artifact: livetest-os-${{ parameters.vmImage }}-powershell-${{ parameters.psVersion }}
targetPath: $(LiveTestDataLocation)
targetPath: $(DataLocation)
condition: always()
80 changes: 80 additions & 0 deletions src/KeyVault/KeyVault.Test/LiveTests/TestLiveScenarios.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Invoke-LiveTestScenario -Name "Create new standard key vault" -Description "Test creating a new standard key vault with all default values" -ScenarioScript `
{
param ($rg)

$rgName = $rg.ResourceGroupName
$vaultName = New-LiveTestResourceName
$vaultLocation = "westus"

$actual = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation
Assert-AreEqual $vaultName $actual.VaultName
Assert-AreEqual $rgName $actual.ResourceGroupName
Assert-AreEqual $vaultLocation $actual.Location
Assert-AreEqual "Standard" $actual.Sku
Assert-AreEqual $false $actual.EnabledForDeployment
Assert-True { $actual.EnableSoftDelete } "By default EnableSoftDelete should be true"
Assert-Null $actual.EnablePurgeProtection "By default EnablePurgeProtection should be null"
Assert-False { $actual.EnableRbacAuthorization } "By default EnableRbacAuthorization should be false"
Assert-AreEqual 90 $actual.SoftDeleteRetentionInDays "By default SoftDeleteRetentionInDays should be 90"
}

Invoke-LiveTestScenario -Name "Create new premium key vault" -Description "Test creating a new premium key vault with all default values" -ScenarioScript `
{
param ($rg)

$rgName = $rg.ResourceGroupName
$vaultName = New-LiveTestResourceName
$vaultLocation = "eastus"

$actual = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation -Sku premium -EnabledForDeployment
Assert-AreEqual $vaultName $actual.VaultName
Assert-AreEqual $rgName $actual.ResourceGroupName
Assert-AreEqual $vaultLocation $actual.Location
Assert-AreEqual "Premium" $actual.Sku
Assert-AreEqual $true $actual.EnabledForDeployment
}

Invoke-LiveTestScenario -Name "Update key vault" -Description "Test updating properties EnableRbacAuthorization and Tag for existing key vault" -ScenarioScript `
{
param ($rg)

$rgName = $rg.ResourceGroupName
$vaultName = New-LiveTestResourceName
$vaultLocation = "eastus"

# Update EnableRbacAuthorization
$vault = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $true
Assert-True { $vault.EnableRbacAuthorization } "EnableRbacAuthorization should be true"

$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $false
Assert-False { $vault.EnableRbacAuthorization } "EnableRbacAuthorization should be false"

# Update Tags
$vault = $vault | Update-AzKeyVault -Tag @{ key = "value" }
Assert-AreEqual 1 $vault.Tags.Count "Tags should contain a key-value pair (key, value)"
Assert-True { $vault.Tags.Contains("key") } "Tags should contain a key-value pair (key, value)"
Assert-AreEqual "value" $vault.Tags["key"] "Tags should contain a key-value pair (key, value)"

# Clean Tags
$vault = $vault | Update-AzKeyVault -Tag @{}
Assert-AreEqual 0 $vault.Tags.Count "Tags should be empty"
}

Invoke-LiveTestScenario -Name "Delete key vault" -Description "Test deleting key vault" -ScenarioScript `
{
param ($rg)

$rgName = $rg.ResourceGroupName
$vaultName = New-LiveTestResourceName
$vaultLocation = "westus"

New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgname -Location $vaultLocation
Remove-AzKeyVault -VaultName $vaultName -Force

$deletedVault = Get-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName
Assert-Null $deletedVault

# purge deleted vault
Remove-AzKeyVault -VaultName $vaultName -Location $vaultLocation -InRemovedState -Force
}
Loading