Replace current validates with pester testing approach #5 (#1232)

* ,oving to the pester approach part #5

* moving to the pester approach part #5

* fixed PostgreSQL tests

* return Validate-Svn.ps1

* fixed Selenium test

* fixed rust test

* fix rust test
This commit is contained in:
Aleksandr Chebotov
2020-07-20 18:57:00 +03:00
committed by GitHub
parent 956b8a0093
commit 0c4dca229d
18 changed files with 145 additions and 161 deletions

View File

@@ -173,12 +173,6 @@
"{{ template_dir }}/scripts/Installers/Validate-Docker.ps1" "{{ template_dir }}/scripts/Installers/Validate-Docker.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PowershellCore.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -275,12 +269,6 @@
"{{ template_dir }}/scripts/Installers/Validate-WDK.ps1" "{{ template_dir }}/scripts/Installers/Validate-WDK.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-ServiceFabricSDK.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -522,12 +510,6 @@
"{{ template_dir }}/scripts/Installers/Install-MysqlCli.ps1" "{{ template_dir }}/scripts/Installers/Install-MysqlCli.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PostgreSQL.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -708,18 +690,6 @@
"{{ template_dir }}/scripts/Installers/Validate-AzCopy.ps1" "{{ template_dir }}/scripts/Installers/Validate-AzCopy.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Rust.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Sbt.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[

View File

@@ -181,12 +181,6 @@
"{{ template_dir }}/scripts/Installers/Validate-Docker.ps1" "{{ template_dir }}/scripts/Installers/Validate-Docker.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PowershellCore.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -268,12 +262,6 @@
"{{ template_dir }}/scripts/Installers/Validate-WDK.ps1" "{{ template_dir }}/scripts/Installers/Validate-WDK.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-ServiceFabricSDK.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -701,24 +689,12 @@
"{{ template_dir }}/scripts/Installers/Validate-AzCopy.ps1" "{{ template_dir }}/scripts/Installers/Validate-AzCopy.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Rust.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Svn.ps1" "{{ template_dir }}/scripts/Installers/Validate-Svn.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Sbt.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -767,12 +743,6 @@
"{{ template_dir }}/scripts/Installers/Validate-Vcpkg.ps1" "{{ template_dir }}/scripts/Installers/Validate-Vcpkg.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PostgreSQL.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[

View File

@@ -19,7 +19,7 @@ function Get-WhichTool($tool) {
# Gets value of environment variable by the name # Gets value of environment variable by the name
function Get-EnvironmentVariable($variable) { function Get-EnvironmentVariable($variable) {
return [System.Environment]::GetEnvironmentVariable($variable) return [System.Environment]::GetEnvironmentVariable($variable, "Machine")
} }
# Update environment variables without reboot # Update environment variables without reboot

View File

@@ -19,7 +19,25 @@ $pgBin = Split-Path -Path $pgPath.split('"')[1]
$pgRoot = Split-Path -Path $pgPath.split('"')[5] $pgRoot = Split-Path -Path $pgPath.split('"')[5]
$pgData = Join-Path $pgRoot "data" $pgData = Join-Path $pgRoot "data"
#Validate PostgreSQL installation
$pgReadyPath = Join-Path $pgBin "pg_isready.exe"
$pgReady = Start-Process -FilePath $pgReadyPath -Wait -PassThru
$exitCode = $pgReady.ExitCode
if ($exitCode -ne 0)
{
Write-Host -Object "PostgreSQL is not ready. Exitcode: $exitCode"
exit $exitCode
}
#Added PostgreSQL environment variable #Added PostgreSQL environment variable
Set-SystemVariable -SystemVariable PGBIN -Value $pgBin Set-SystemVariable -SystemVariable PGBIN -Value $pgBin
Set-SystemVariable -SystemVariable PGROOT -Value $pgRoot Set-SystemVariable -SystemVariable PGROOT -Value $pgRoot
Set-SystemVariable -SystemVariable PGDATA -Value $pgData Set-SystemVariable -SystemVariable PGDATA -Value $pgData
#Stop and disable PostgreSQL service
$pgService = Get-Service -Name postgresql*
Stop-Service -InputObject $pgService
Set-Service -InputObject $pgService -StartupType Disabled
Invoke-PesterTests -TestFile "Databases" -TestName "PostgreSQL"

View File

@@ -4,3 +4,5 @@
################################################################################ ################################################################################
Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet" Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"
Invoke-PesterTests -TestFile "Tools" -TestName "PowerShell Core"

View File

@@ -6,8 +6,8 @@
Import-Module -Name ImageHelpers Import-Module -Name ImageHelpers
# Rust Env # Rust Env
$env:RUSTUP_HOME="C:\Rust\.rustup" $env:RUSTUP_HOME = "C:\Rust\.rustup"
$env:CARGO_HOME="C:\Rust\.cargo" $env:CARGO_HOME = "C:\Rust\.cargo"
# Download the latest rustup-init.exe for Windows x64 # Download the latest rustup-init.exe for Windows x64
# See https://rustup.rs/# # See https://rustup.rs/#
@@ -49,3 +49,10 @@ Remove-Item "${env:CARGO_HOME}\registry\*" -Recurse -Force
# Update Run key to run a script at logon # Update Run key to run a script at logon
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "RUSTSYM" -Value $cmdPath Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "RUSTSYM" -Value $cmdPath
# Create temporary symlinks to properly validate tools version
Set-Location -Path $env:UserProfile
$null = New-Item -Name ".rustup" -Value $env:RUSTUP_HOME -ItemType Junction
$null = New-Item -Name ".cargo" -Value $env:CARGO_HOME -ItemType Junction
Invoke-PesterTests -TestFile "Rust"

View File

@@ -14,7 +14,5 @@ $env:SBT_HOME="${env:ProgramFiles(x86)}\sbt"
# Add sbt binaries to the path # Add sbt binaries to the path
Add-MachinePathItem "$env:SBT_HOME\bin" Add-MachinePathItem "$env:SBT_HOME\bin"
$env:Path = Get-MachinePath
# Done Invoke-PesterTests -TestFile "Tools" -TestName "Sbt"
exit 0

View File

@@ -32,3 +32,5 @@ Start-DownloadWithRetry -Url $seleniumReleaseUrl -Name $seleniumFileName -Downlo
Write-Host "Add selenium jar to the environment variables..." Write-Host "Add selenium jar to the environment variables..."
$seleniumBinPath = Join-Path $seleniumDirectory $seleniumFileName $seleniumBinPath = Join-Path $seleniumDirectory $seleniumFileName
setx "SELENIUM_JAR_PATH" "$($seleniumBinPath)" /M setx "SELENIUM_JAR_PATH" "$($seleniumBinPath)" /M
Invoke-PesterTests -TestFile "Browsers" -TestName "Selenium"

View File

@@ -11,3 +11,5 @@ New-Item -Path $temp_install_dir -ItemType Directory -Force
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
WebpiCmd.exe /Install /Products:MicrosoftAzure-ServiceFabric-CoreSDK /AcceptEula /XML:https://webpifeed.blob.core.windows.net/webpifeed/5.1/WebProductList.xml WebpiCmd.exe /Install /Products:MicrosoftAzure-ServiceFabric-CoreSDK /AcceptEula /XML:https://webpifeed.blob.core.windows.net/webpifeed/5.1/WebProductList.xml
Invoke-PesterTests -TestFile "Tools" -TestName "ServiceFabricSDK"

View File

@@ -1,18 +0,0 @@
$pgReadyPath = Join-Path ${env:PGBIN} "pg_isready.exe"
$pgReady = Start-Process -FilePath $pgReadyPath -Wait -PassThru
$exitCode = $pgReady.ExitCode
if ($exitCode -eq 0)
{
Write-Host -Object "PostgreSQL has been successfully installed."
}
else
{
Write-Host -Object "PostgreSQL is not ready. Exitcode: $exitCode"
exit $exitCode
}
#Stop and disable PostgreSQL service
$pgService = Get-Service -Name postgresql*
Stop-Service -InputObject $pgService
Set-Service -InputObject $pgService -StartupType Disabled

View File

@@ -1,15 +0,0 @@
################################################################################
## File: Validate-PowershellCore.ps1
## Desc: Validate Powershell Core
################################################################################
if (Get-Command -Name 'pwsh')
{
Write-Host 'pwsh is on PATH'
}
else
{
Write-Host 'pwsh is not on PATH'
exit 1
}

View File

@@ -1,29 +0,0 @@
################################################################################
## File: Validate-Rust.ps1
## Desc: Verify that Rust is on the path and output version information.
################################################################################
if (Get-Command -Name 'rustc')
{
Push-Location -Path $env:UserProfile
New-Item -Name ".rustup" -Value "C:\Rust\.rustup" -ItemType Junction
New-Item -Name ".cargo" -Value "C:\Rust\.cargo" -ItemType Junction
$RustcVersion = rustc --version
Write-Host "$RustcVersion is on the path"
Pop-Location
}
else
{
Write-Host "rustc is not on the path"
exit 1
}
if (-Not (Get-Command -Name 'cargo-audit')){
Write-Host "cargo audit is not on the path"
exit 1
}
if (-Not (Get-Command -Name 'cargo-outdated')){
Write-Host "cargo outdated is not on the path"
exit 1
}

View File

@@ -1,15 +0,0 @@
################################################################################
## File: Validate-Sbt.ps1
## Desc: Validate sbt for Windows
################################################################################
if (Get-Command -Name 'sbt')
{
Write-Host 'sbt is on the path'
}
else
{
Write-Host 'sbt is not on path.'
exit 1
}

View File

@@ -1,17 +0,0 @@
################################################################################
## File: Validate-ServiceFabricSDK.ps1
## Desc: Validate ServiceFabricSDK
################################################################################
$modules = Get-Module -Name ServiceFabric -ListAvailable
if (($modules | Measure-Object).Count -gt 0)
{
$modules
}
else
{
Write-Host "ServiceFabric Module is not present, it might not be installed"
throw "ServiceFabric Module is not present, it might not be installed"
}

View File

@@ -133,4 +133,18 @@ Describe "Internet Explorer" {
"$env:IEWebDriver\versioninfo.txt" | Should -Exist "$env:IEWebDriver\versioninfo.txt" | Should -Exist
} }
} }
}
Describe "Selenium" {
It "Selenium 'C:\selenium' path exists" {
"C:\selenium" | Should -Exist
}
It "Selenium Server 'selenium-server-standalone.jar' is installed" {
"C:\selenium\selenium-server-standalone.jar" | Should -Exist
}
It "SELENIUM_JAR_PATH environment variable exists" {
Get-EnvironmentVariable "SELENIUM_JAR_PATH" | Should -BeExactly "C:\selenium\selenium-server-standalone.jar"
}
} }

View File

@@ -6,9 +6,55 @@ Describe "MongoDB" {
"$ToolName --version" | Should -ReturnZeroExitCode "$ToolName --version" | Should -ReturnZeroExitCode
} }
} }
Describe "PostgreSQL" {
$psqlTests = @(
@{envVar = "PGROOT"; pgPath = Get-EnvironmentVariable "PGROOT"}
@{envVar = "PGBIN"; pgPath = Get-EnvironmentVariable "PGBIN"}
@{envVar = "PGDATA"; pgPath = Get-EnvironmentVariable "PGDATA"}
)
Context "Environment variable" {
It "PGUSER contains postgres" {
Get-EnvironmentVariable "PGUSER" | Should -Be "postgres"
}
It "PGPASSWORD contains root" {
Get-EnvironmentVariable "PGPASSWORD" | Should -Be "root"
}
It "<envVar> environment variable exists" -TestCases $psqlTests {
Get-EnvironmentVariable $envVar | Should -Not -BeNullOrEmpty
}
}
Context "Path" {
It "<pgPath> path exists" -TestCases $psqlTests {
$pgPath | Should -Exist
}
}
Context "Service" {
$psqlService = Get-Service -Name postgresql*
$psqlServiceTests = @{
Name = $psqlService.Name
Status = $psqlService.Status
StartType = $psqlService.StartType
}
It "<Name> service is stopped" -TestCases $psqlServiceTests {
$Status | Should -Be "Stopped"
}
It "<Name> service is disabled" -TestCases $psqlServiceTests {
$StartType | Should -Be "Disabled"
}
}
}
Describe "MySQL" { Describe "MySQL" {
It "MySQL CLI" { It "MySQL CLI" {
"mysql -V" | Should -ReturnZeroExitCode "mysql -V" | Should -ReturnZeroExitCode
} }
} }

View File

@@ -0,0 +1,27 @@
Describe "Rust" {
$rustTools = @(
@{ToolName = "rustup"; binPath = "C:\Rust\.cargo\bin\rustup.exe"}
@{ToolName = "rustc"; binPath = "C:\Rust\.cargo\bin\rustc.exe"}
@{ToolName = "cargo"; binPath = "C:\Rust\.cargo\bin\cargo.exe"}
@{ToolName = "cargo audit"; binPath = "C:\Rust\.cargo\bin\cargo-audit.exe"}
@{ToolName = "cargo outdated"; binPath = "C:\Rust\.cargo\bin\cargo-outdated.exe"}
)
$rustEnvNotExists = @(
@{envVar = "RUSTUP_HOME"}
@{envVar = "CARGO_HOME"}
)
It "C:\Rust\.rustup and C:\Rust\.cargo folders exist" {
"C:\Rust\.rustup", "C:\Rust\.cargo" | Should -Exist
}
It "<envVar> environment variable does not exist" -TestCases $rustEnvNotExists {
[Environment]::GetEnvironmentVariables("Machine").ContainsKey($envVar) | Should -BeFalse
}
It "<ToolName> is installed to the '<binPath>' folder" -TestCases $rustTools {
"$ToolName --version" | Should -ReturnZeroExitCode
$binPath | Should -Exist
}
}

View File

@@ -133,4 +133,26 @@ Describe "Perl" {
It "Perl" { It "Perl" {
"perl --version" | Should -ReturnZeroExitCode "perl --version" | Should -ReturnZeroExitCode
} }
}
Describe "PowerShell Core" {
It "pwsh" {
"pwsh --version" | Should -ReturnZeroExitCode
}
It "Execute 2+2 command" {
pwsh -Command "2+2" | Should -BeExactly 4
}
}
Describe "Sbt" {
It "sbt" {
"sbt --version" | Should -ReturnZeroExitCode
}
}
Describe "ServiceFabricSDK" {
It "PowerShell Module" {
Get-Module -Name ServiceFabric -ListAvailable | Should -Not -BeNullOrEmpty
}
} }