Replace current validates with pester testing approach #1 (#1253)

* first part

* fix session manager plugin

* rework AWS installation

* azure cosmos db tests

* azure devops cli

* add azmodules test

* put brackets

* add root folder

* remove validate aliyun

* add azure modules

* update modules test

* docker, baze, dotnetsdk

* DACFx

* add azdevopscli

* change to Should -BeTrue

* nitpicks

* remove extra

* add azurecli

* remove BeforeAll for DACFx

* a bit of refactoring

* fix templates

* remove disk space validation

* rename to powershell modules

* fix templates
This commit is contained in:
Mikhail Timofeev
2020-07-21 09:50:01 +03:00
committed by GitHub
parent 123b675a4d
commit 23aade159c
27 changed files with 190 additions and 413 deletions

View File

@@ -1,7 +0,0 @@
################################################################################
## File: Install-AWS-SAM.ps1
## Desc: Install aws sam cli
## https://aws.amazon.com/serverless/sam/
################################################################################
Install-Binary -Url "https://github.com/awslabs/aws-sam-cli/releases/latest/download/AWS_SAM_CLI_64_PY3.msi" -Name "AWS_SAM_CLI_64_PY3.msi"

View File

@@ -1,28 +1,18 @@
################################################################################
## File: Install-awscli.ps1
## Desc: Install awscli
## File: Install-AWS.ps1
## Desc: Install AWS tools(AWS CLI, Session Manager Plugin for the AWS CLI, AWS SAM CLI)
################################################################################
# Install AWS CLI
Choco-Install -PackageName awscli
$env:Path = $env:Path + ";$env:ProgramFiles\Amazon\AWSCLIV2"
if (Get-Command -Name 'aws')
{
Write-Host 'awscli on path'
}
else
{
Write-Host 'awscli is not on path'
exit 1
}
# Install Session Manager Plugin for the AWS CLI
$sessionManagerName = "SessionManagerPluginSetup.exe"
$sessionManagerUrl = "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/windows/$sessionManagerName"
Install-Binary -Url $sessionManagerUrl -Name $sessionManagerName -ArgumentList ("/silent", "/install")
$env:Path = $env:Path + ";$env:ProgramFiles\Amazon\SessionManagerPlugin\bin"
$sessionMessage = session-manager-plugin
Write-Host "$sessionMessage"
if ($sessionMessage -notmatch "*plugin was installed successfully*") {
exit 1
}
# Install AWS SAM CLI
Install-Binary -Url "https://github.com/awslabs/aws-sam-cli/releases/latest/download/AWS_SAM_CLI_64_PY3.msi" -Name "AWS_SAM_CLI_64_PY3.msi"
Invoke-PesterTests -TestFile "Tools" -TestName "AWS"

View File

@@ -3,4 +3,6 @@
## Desc: Install Alibaba Cloud CLI
################################################################################
Choco-Install -PackageName aliyun-cli
Choco-Install -PackageName aliyun-cli
Invoke-PesterTests -TestFile "Tools" -TestName "AliyunCli"

View File

@@ -3,4 +3,6 @@
## Desc: Install AzCopy10
################################################################################
Choco-Install -PackageName azcopy10
Choco-Install -PackageName azcopy10
Invoke-PesterTests -TestFile "Tools" -TestName "AzCopy"

View File

@@ -10,3 +10,4 @@ New-Item -ItemType "directory" -Path $AzureCliExtensionPath
[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $AzureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
Invoke-PesterTests -TestFile "Tools" -TestName "AzureCli"

View File

@@ -8,4 +8,6 @@ Import-Module -Name ImageHelpers -Force
$InstallerName = "AzureCosmosDBEmulator.msi"
$InstallerUrl = "https://aka.ms/cosmosdb-emulator"
Install-Binary -Url $InstallerUrl -Name $InstallerName
Install-Binary -Url $InstallerUrl -Name $InstallerName
Invoke-PesterTests -TestFile "Tools" -TestName "Azure Cosmos DB Emulator"

View File

@@ -4,3 +4,5 @@
################################################################################
az extension add -n azure-devops
Invoke-PesterTests -TestFile "Tools" -TestName "Azure DevOps CLI"

View File

@@ -52,4 +52,6 @@ foreach ($module in $modules)
# Add modules to the PSModulePath
$psModuleMachinePath += $env:PSModulePath
[Environment]::SetEnvironmentVariable("PSModulePath", $psModuleMachinePath, "Machine")
[Environment]::SetEnvironmentVariable("PSModulePath", $psModuleMachinePath, "Machine")
Invoke-PesterTests -TestFile "PowerShellModules" -TestName "AzureModules"

View File

@@ -5,4 +5,6 @@
Choco-Install -PackageName bazel
npm install -g @bazel/bazelisk
npm install -g @bazel/bazelisk
Invoke-PesterTests -TestFile "Tools" -TestName "Bazel"

View File

@@ -8,4 +8,6 @@ Import-Module -Name ImageHelpers -Force
$InstallerName = "DacFramework.msi"
$InstallerUrl = "https://go.microsoft.com/fwlink/?linkid=2128142"
Install-Binary -Url $InstallerUrl -Name $InstallerName
Install-Binary -Url $InstallerUrl -Name $InstallerName
Invoke-PesterTests -TestFile "Tools" -TestName "DACFx"

View File

@@ -17,4 +17,6 @@ Write-Host "Install-Package Docker-Compose"
Choco-Install -PackageName docker-compose
Write-Host "Install Helm"
Choco-Install -PackageName kubernetes-helm
Choco-Install -PackageName kubernetes-helm
Invoke-PesterTests -TestFile "Tools" -TestName "Docker"

View File

@@ -113,3 +113,5 @@ function RunPostInstallationSteps()
InstallAllValidSdks
RunPostInstallationSteps
Invoke-PesterTests -TestFile "DotnetSDK"

View File

@@ -1,14 +0,0 @@
################################################################################
## File: Validate-AWS-SAM.ps1
## Desc: Validate aws sam cli
################################################################################
if (Get-Command -Name 'sam')
{
Write-Host 'AWS SAM CLI on path'
}
else
{
Write-Host 'AWS SAM CLI is not on path'
exit 1
}

View File

@@ -1,14 +0,0 @@
################################################################################
## File: Validate-AliyunCli.ps1
## Desc: Validate Alibaba Cloud CLI
################################################################################
if (Get-Command -Name 'aliyun')
{
Write-Host 'Alibaba Cloud CLI on path'
}
else
{
Write-Host 'Alibaba Cloud CLI is not on path'
exit 1
}

View File

@@ -1,10 +0,0 @@
################################################################################
## File: Validate-AzCopy.ps1
## Desc: Validate AzCopy10
################################################################################
if (Get-Command -Name 'azcopy') {
Write-Host "$(azcopy --version) on path"
} else {
Write-Error "azcopy not on path"
exit 1
}

View File

@@ -1,38 +0,0 @@
################################################################################
## File: Validate-AzureCosmosDbEmulator.ps1
## Desc: Validate Azure CosmosDb Emulator installation.
################################################################################
$SoftwareName = 'Azure CosmosDb Emulator'
$regKey = gci HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | gp | ? { $_.DisplayName -eq 'Azure Cosmos DB Emulator' }
if ($regKey -eq $null)
{
Write-Host "The $regKey registry key is not set"
exit 1
}
else
{
Write-Host "The $regKey registry key is set"
}
$installDir = $regKey.InstallLocation
if ($installDir -eq $null)
{
Write-Host "The $SoftwareName installation directory registry value is not set"
exit 1
}
else
{
Write-Host "The $SoftwareName installation directory registry value is set to: $installDir"
}
$exeFilePath = Join-Path $installDir 'CosmosDB.Emulator.exe'
if (!(Test-Path $exeFilePath))
{
Write-Host "$SoftwareName is not installed"
exit 1
}
$fileVersion = (Get-Item $exeFilePath).VersionInfo.FileVersion
Write-Host "$SoftwareName is successfully installed: $fileVersion"

View File

@@ -1,17 +0,0 @@
################################################################################
## File: Validate-AzureDevOpsCli.ps1
## Desc: Validate Azure DevOps CLI
################################################################################
az devops -h
if ($LastExitCode -ne 0)
{
Write-Error "Azure DevOps Cli extension not present"
exit 1
}
else
{
Write-Host "Azure DevOps Cli extension is present"
}

View File

@@ -1,44 +0,0 @@
################################################################################
## File: Validate-AzureModules.ps1
## Desc: Validate Azure PowerShell modules
################################################################################
$ErrorActionPreference = "Stop"
$modulesRootPath = $env:PSMODULES_ROOT_FOLDER
# Get modules content from toolset
$modules = (Get-ToolsetContent).azureModules
foreach ($module in $modules)
{
foreach ($version in $module.versions)
{
$moduleName = $module.name
$modulePath = Join-Path -Path $modulesRootPath -ChildPath "$($module.name)_${version}"
Write-Host "Trying to import ${moduleName}_${version}..."
$testJob = Start-Job -ScriptBlock {
param (
$modulePath,
$moduleName
)
$env:PsModulePath = "$modulePath;$env:PsModulePath"
Import-Module -Name $moduleName
Get-Module -Name $moduleName
} -ArgumentList $modulePath, $moduleName
$isError = $testJob | Wait-Job | Foreach-Object ChildJobs | Where-Object { $_.Error }
if ($isError)
{
Write-Host "Required ${moduleName} module ${version} version is not present"
exit 1
}
$testJob | Receive-Job | Select-Object Name,Version,Path
Remove-Job $testJob
}
}

View File

@@ -1,26 +0,0 @@
################################################################################
## File: Validate-Bazel.ps1
## Desc: Validate Bazel and Bazelisk (A user-friendly launcher for Bazel)
################################################################################
if (Get-Command -Name 'bazel')
{
Write-Host 'bazel on path'
}
else
{
Write-Host 'bazel is not on path'
exit 1
}
if (Get-Command -Name 'bazelisk')
{
Write-Host 'bazelisk on path'
}
else
{
Write-Host 'bazelisk is not on path'
exit 1
}

View File

@@ -1,24 +0,0 @@
####################################################################################
## File: Validate-DACFx.ps1
## Desc: Validate SQL Server® Data-Tier Application Framework (DACFx) for Windows
####################################################################################
$env:PATH = $env:Path + ';C:\Program Files\Microsoft SQL Server\120\DAC\bin;C:\Program Files\Microsoft SQL Server\130\DAC\bin;C:\Program Files\Microsoft SQL Server\140\DAC\bin;C:\Program Files\Microsoft SQL Server\150\DAC\bin'
if (Get-Command -Name 'SqlPackage')
{
Write-Host "DACFx is installed at path" (Get-Command -Name 'SqlPackage').Source
}
else
{
throw "DACFx is not installed!"
}
if (Get-Command -Name 'SqlLocalDB')
{
Write-Host "SQL Server Express LocalDB is available at " (Get-Command -Name SqlLocalDB).Source
}
else
{
throw "SqlLocalDB is not installed!"
}

View File

@@ -1,26 +0,0 @@
################################################################################
## File: Validate-Docker.ps1
## Desc: Validate Docker.
################################################################################
if ((Get-Command -Name 'docker') -and (Get-Command -Name 'docker-compose'))
{
Write-Host "docker $(docker version) on path"
Write-Host "docker-compose $(docker-compose version) on path"
}
else
{
Write-Host "docker or docker-compose are not on path"
exit 1
}
# Validate helm
if (Get-Command -Name 'helm')
{
Write-Host "helm on path"
}
else
{
Write-Host 'helm is not on path'
exit 1
}

View File

@@ -1,16 +0,0 @@
################################################################################
## File: Validate-DotnetSDK.ps1
## Desc: Validate dotnet
################################################################################
if (Get-Command -Name 'dotnet')
{
Write-Host "dotnet $(dotnet --version) on path"
}
else
{
Write-Host "dotnet is not on path"
exit 1
}