mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 02:41:39 +00:00
Update Playwright, improve E2E test reliability, add scripts to deploy test resources (#1857)
This commit is contained in:
committed by
GitHub
parent
736731474f
commit
417ef899f0
4
test/resources/README.md
Normal file
4
test/resources/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Azure Resources for E2E Testing
|
||||
|
||||
This directory contains Bicep files for creating the necessary Azure resources for end-to-end testing.
|
||||
To deploy the resources, run the './deploy.ps1' script in this directory and follow the prompts.
|
||||
50
test/resources/account.bicep
Normal file
50
test/resources/account.bicep
Normal file
@@ -0,0 +1,50 @@
|
||||
targetScope = 'resourceGroup'
|
||||
|
||||
@description('The name of the account to create/update. If the account already exists, it will be updated.')
|
||||
param accountName string
|
||||
@description('The name of the owner of this account, usually a Microsoft alias, but can be any string.')
|
||||
param ownerName string
|
||||
@description('The Azure location in which to create the account.')
|
||||
param location string
|
||||
@description('The total throughput limit for the account. Defaults to 10000 RU/s.')
|
||||
param totalThroughputLimit int = 10000
|
||||
@allowed([
|
||||
'tables'
|
||||
'cassandra'
|
||||
'gremlin'
|
||||
'mongo'
|
||||
'mongo32'
|
||||
'sql'
|
||||
])
|
||||
@description('The type of account to create.')
|
||||
param testAccountType string
|
||||
|
||||
var kind = (testAccountType == 'mongo' || testAccountType == 'mongo32') ? 'MongoDB' : 'GlobalDocumentDB'
|
||||
var capabilities = (testAccountType == 'tables') ? [{name: 'EnableTable'}] : (testAccountType == 'cassandra') ? [{name: 'EnableCassandra'}] : (testAccountType == 'gremlin') ? [{name: 'EnableGremlin'}] : []
|
||||
var serverVersion = (testAccountType == 'mongo32') ? '3.2' : (testAccountType == 'mongo') ? '6.0' : null
|
||||
|
||||
resource testCosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2024-02-15-preview' = {
|
||||
name: accountName
|
||||
location: location
|
||||
tags: {
|
||||
'DataExplorer:TestAccountType': testAccountType
|
||||
Owner: ownerName
|
||||
}
|
||||
kind: kind
|
||||
properties: {
|
||||
databaseAccountOfferType: 'Standard'
|
||||
locations: [
|
||||
{
|
||||
locationName: location
|
||||
failoverPriority: 0
|
||||
}
|
||||
]
|
||||
apiProperties: {
|
||||
serverVersion: serverVersion
|
||||
}
|
||||
capabilities: capabilities
|
||||
capacity: {
|
||||
totalThroughputLimit: totalThroughputLimit
|
||||
}
|
||||
}
|
||||
}
|
||||
31
test/resources/all-accounts.bicep
Normal file
31
test/resources/all-accounts.bicep
Normal file
@@ -0,0 +1,31 @@
|
||||
@description('A prefix to apply to the name of each account.')
|
||||
param accountPrefix string
|
||||
@description('The name of the owner of this account, usually a Microsoft alias, but can be any string.')
|
||||
param ownerName string
|
||||
@description('The Azure location in which to create the account.')
|
||||
param location string
|
||||
@description('The total throughput limit for the account. Defaults to 10000 RU/s.')
|
||||
param totalThroughputLimit int = 10000
|
||||
@allowed([
|
||||
'tables'
|
||||
'cassandra'
|
||||
'gremlin'
|
||||
'mongo'
|
||||
'mongo32'
|
||||
'sql'
|
||||
])
|
||||
@description('The type of accounts to create.')
|
||||
param testAccountTypes string[]
|
||||
|
||||
var actualPrefix = endsWith(accountPrefix, '-') ? accountPrefix : '${accountPrefix}-'
|
||||
|
||||
module testAccount './account.bicep' = [for testAccountType in testAccountTypes: {
|
||||
name: '${actualPrefix}${testAccountType}'
|
||||
params: {
|
||||
accountName: '${actualPrefix}${testAccountType}'
|
||||
ownerName: ownerName
|
||||
location: location
|
||||
totalThroughputLimit: totalThroughputLimit
|
||||
testAccountType: testAccountType
|
||||
}
|
||||
}]
|
||||
31
test/resources/create-resource-group.ps1
Normal file
31
test/resources/create-resource-group.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$Subscription,
|
||||
[Parameter(Mandatory=$false)][string]$ResourceGroupName,
|
||||
[Parameter(Mandatory=$true)][string]$Location
|
||||
)
|
||||
|
||||
Import-Module "Az.Accounts" -Scope Local
|
||||
Import-Module "Az.Resources" -Scope Local
|
||||
|
||||
$AzSubscription = (Get-AzSubscription -SubscriptionId $Subscription -ErrorAction SilentlyContinue) ?? (Get-AzSubscription -SubscriptionName $Subscription -ErrorAction SilentlyContinue)
|
||||
if(-not $AzSubscription) {
|
||||
throw "The subscription '$Subscription' could not be found."
|
||||
}
|
||||
|
||||
Select-AzSubscription -SubscriptionId $Subscription
|
||||
|
||||
if(-not $ResourceGroupName) {
|
||||
$ResourceGroupName = $env:USERNAME + "-e2e-testing"
|
||||
}
|
||||
|
||||
$AzResourceGroup = Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue
|
||||
if($AzResourceGroup) {
|
||||
Write-Host "The resource group '$ResourceGroupName' already exists."
|
||||
return
|
||||
}
|
||||
|
||||
$confirm = Read-Host "Do you want to create the resource group '$ResourceGroupName' in the location '$Location'? (y/n)"
|
||||
if($confirm -ne "y") {
|
||||
throw "The resource group creation was cancelled."
|
||||
}
|
||||
$AzResourceGroup = New-AzResourceGroup -Name $ResourceGroupName -Location $Location
|
||||
113
test/resources/deploy.ps1
Normal file
113
test/resources/deploy.ps1
Normal file
@@ -0,0 +1,113 @@
|
||||
param(
|
||||
[Parameter(Mandatory=$false)][string]$ResourceGroup,
|
||||
[Parameter(Mandatory=$false)][string]$Subscription,
|
||||
[Parameter(Mandatory=$false)][string]$Location,
|
||||
[Parameter(Mandatory=$false)][string]$ResourcePrefix,
|
||||
[ValidateSet("tables", "cassandra", "gremlin", "mongo", "mongo32", "sql")] # This must be a constant so we can't re-use the $AllResourceTypes variable :(
|
||||
[Parameter(Mandatory=$false)][string[]]$ResourceSets,
|
||||
[Parameter(Mandatory=$false)][string]$OwnerName,
|
||||
[Parameter(Mandatory=$false)][int]$TotalThroughputLimit = 10000,
|
||||
[Parameter(Mandatory=$false)][switch]$WhatIf
|
||||
)
|
||||
|
||||
$AllResourceTypes = @(
|
||||
"tables",
|
||||
"cassandra",
|
||||
"gremlin",
|
||||
"mongo",
|
||||
"mongo32",
|
||||
"sql"
|
||||
)
|
||||
|
||||
Import-Module "Az.Accounts" -Scope Local
|
||||
Import-Module "Az.Resources" -Scope Local
|
||||
|
||||
if (-not (Get-Command bicep -ErrorAction SilentlyContinue)) {
|
||||
throw "The Bicep CLI is required to run this script. Please install it first."
|
||||
}
|
||||
|
||||
if (-not (Get-AzContext)) {
|
||||
throw "Please login to your Azure account using Connect-AzAccount before running this script."
|
||||
}
|
||||
|
||||
if(-not $ResourcePrefix) {
|
||||
$ResourcePrefix = $env:USERNAME + "-e2e-"
|
||||
}
|
||||
|
||||
if(-not $OwnerName) {
|
||||
$OwnerName = $env:USERNAME
|
||||
}
|
||||
|
||||
if (-not $Subscription) {
|
||||
# Show the user the currently-selected subscription and ask if that's what they want to use
|
||||
$currentSubscription = Get-AzContext | Select-Object -ExpandProperty Subscription
|
||||
Write-Host "The currently-selected subscription is $($currentSubscription.Name) ($($currentSubscription.Id))."
|
||||
$useCurrentSubscription = Read-Host "Do you want to use this subscription? (y/n)"
|
||||
if ($useCurrentSubscription -eq "n") {
|
||||
throw "Either specify a subscription using '-Subscription' or select a subscription using 'Select-AzSubscription' before running this script."
|
||||
}
|
||||
$Subscription = $currentSubscription.Id
|
||||
}
|
||||
|
||||
$AzSubscription = (Get-AzSubscription -SubscriptionId $Subscription -ErrorAction SilentlyContinue) ?? (Get-AzSubscription -SubscriptionName $Subscription -ErrorAction SilentlyContinue)
|
||||
if (-not $AzSubscription) {
|
||||
throw "The subscription '$Subscription' could not be found."
|
||||
}
|
||||
|
||||
Set-AzContext $AzSubscription | Out-Null
|
||||
|
||||
if (-not $ResourceGroup) {
|
||||
$DefaultResourceGroupName = $env:USERNAME + "-e2e-testing"
|
||||
if (Get-AzResourceGroup -Name $DefaultResourceGroupName -ErrorAction SilentlyContinue) {
|
||||
Write-Host "Found a resource group with the default name ($DefaultResourceGroupName). Using that resource group. If you want to use a different resource group, specify it as a parameter."
|
||||
$ResourceGroup = $DefaultResourceGroupName
|
||||
} else {
|
||||
$ResourceGroup = Read-Host "Specify the name of the resource group to deploy the resources to."
|
||||
}
|
||||
}
|
||||
|
||||
$AzResourceGroup = Get-AzResourceGroup -Name $ResourceGroup -ErrorAction SilentlyContinue
|
||||
if (-not $AzResourceGroup) {
|
||||
throw "The resource group '$ResourceGroup' could not be found. You have to create the resource group manually before running this script."
|
||||
}
|
||||
|
||||
if (-not $Location) {
|
||||
$Location = $AzResourceGroup.Location
|
||||
}
|
||||
|
||||
$AzLocation = Get-AzLocation | Where-Object { $_.Location -eq $Location }
|
||||
if (-not $AzLocation) {
|
||||
throw "The location '$Location' could not be found."
|
||||
}
|
||||
|
||||
if (-not $ResourceSets) {
|
||||
$ResourceSets = $AllResourceTypes
|
||||
} else {
|
||||
# Normalize the resource set names to the value in AllResourceTypes
|
||||
$ResourceSets = $ResourceSets | ForEach-Object { $_.ToLower() }
|
||||
}
|
||||
|
||||
Write-Host "Deploying test resource sets: $ResourceSets"
|
||||
Write-Host " in $($AzLocation.DisplayName)"
|
||||
Write-Host " to resource group $ResourceGroup"
|
||||
Write-Host " in subscription $($AzSubscription.Name) ($($AzSubscription.Id))."
|
||||
if($WhatIf) {
|
||||
Write-Host " (What-If mode enabled)"
|
||||
}
|
||||
|
||||
$continue = Read-Host "Do you want to continue? (y/n)"
|
||||
if ($continue -ne "y") {
|
||||
throw "Deployment cancelled."
|
||||
}
|
||||
|
||||
$bicepFile = Join-Path $PSScriptRoot "all-accounts.bicep"
|
||||
Write-Host "Deploying resources using $bicepFile"
|
||||
New-AzResourceGroupDeployment `
|
||||
-ResourceGroupName $AzResourceGroup.ResourceGroupName `
|
||||
-TemplateFile $bicepFile `
|
||||
-WhatIf:$WhatIf `
|
||||
-accountPrefix $ResourcePrefix `
|
||||
-testAccountTypes $ResourceSets `
|
||||
-location $AzLocation.Location `
|
||||
-ownerName $OwnerName `
|
||||
-totalThroughputLimit $TotalThroughputLimit
|
||||
Reference in New Issue
Block a user