Skip to content

Commit

Permalink
Replace current validates with pester testing approach #5 (#1232)
Browse files Browse the repository at this point in the history
* ,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
  • Loading branch information
al-cheb authored Jul 20, 2020
1 parent 956b8a0 commit 0c4dca2
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 161 deletions.
30 changes: 0 additions & 30 deletions images/win/Windows2016-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@
"{{ template_dir }}/scripts/Installers/Validate-Docker.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PowershellCore.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -275,12 +269,6 @@
"{{ template_dir }}/scripts/Installers/Validate-WDK.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-ServiceFabricSDK.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -522,12 +510,6 @@
"{{ template_dir }}/scripts/Installers/Install-MysqlCli.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PostgreSQL.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -708,18 +690,6 @@
"{{ 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",
"scripts":[
Expand Down
30 changes: 0 additions & 30 deletions images/win/Windows2019-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@
"{{ template_dir }}/scripts/Installers/Validate-Docker.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PowershellCore.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -268,12 +262,6 @@
"{{ template_dir }}/scripts/Installers/Validate-WDK.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-ServiceFabricSDK.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -701,24 +689,12 @@
"{{ 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-Svn.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Sbt.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -767,12 +743,6 @@
"{{ template_dir }}/scripts/Installers/Validate-Vcpkg.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-PostgreSQL.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down
2 changes: 1 addition & 1 deletion images/win/scripts/ImageHelpers/TestsHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Get-WhichTool($tool) {

# Gets value of environment variable by the name
function Get-EnvironmentVariable($variable) {
return [System.Environment]::GetEnvironmentVariable($variable)
return [System.Environment]::GetEnvironmentVariable($variable, "Machine")
}

# Update environment variables without reboot
Expand Down
18 changes: 18 additions & 0 deletions images/win/scripts/Installers/Install-PostgreSQL.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,25 @@ $pgBin = Split-Path -Path $pgPath.split('"')[1]
$pgRoot = Split-Path -Path $pgPath.split('"')[5]
$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
Set-SystemVariable -SystemVariable PGBIN -Value $pgBin
Set-SystemVariable -SystemVariable PGROOT -Value $pgRoot
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"
2 changes: 2 additions & 0 deletions images/win/scripts/Installers/Install-PowershellCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
################################################################################

Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"

Invoke-PesterTests -TestFile "Tools" -TestName "PowerShell Core"
11 changes: 9 additions & 2 deletions images/win/scripts/Installers/Install-Rust.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Import-Module -Name ImageHelpers

# Rust Env
$env:RUSTUP_HOME="C:\Rust\.rustup"
$env:CARGO_HOME="C:\Rust\.cargo"
$env:RUSTUP_HOME = "C:\Rust\.rustup"
$env:CARGO_HOME = "C:\Rust\.cargo"

# Download the latest rustup-init.exe for Windows x64
# See https://rustup.rs/#
Expand Down Expand Up @@ -49,3 +49,10 @@ Remove-Item "${env:CARGO_HOME}\registry\*" -Recurse -Force

# Update Run key to run a script at logon
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"
4 changes: 1 addition & 3 deletions images/win/scripts/Installers/Install-Sbt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ $env:SBT_HOME="${env:ProgramFiles(x86)}\sbt"

# Add sbt binaries to the path
Add-MachinePathItem "$env:SBT_HOME\bin"
$env:Path = Get-MachinePath

# Done
exit 0
Invoke-PesterTests -TestFile "Tools" -TestName "Sbt"
2 changes: 2 additions & 0 deletions images/win/scripts/Installers/Install-Selenium.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ Start-DownloadWithRetry -Url $seleniumReleaseUrl -Name $seleniumFileName -Downlo
Write-Host "Add selenium jar to the environment variables..."
$seleniumBinPath = Join-Path $seleniumDirectory $seleniumFileName
setx "SELENIUM_JAR_PATH" "$($seleniumBinPath)" /M

Invoke-PesterTests -TestFile "Browsers" -TestName "Selenium"
2 changes: 2 additions & 0 deletions images/win/scripts/Installers/Install-ServiceFabricSDK.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ New-Item -Path $temp_install_dir -ItemType Directory -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

Invoke-PesterTests -TestFile "Tools" -TestName "ServiceFabricSDK"
18 changes: 0 additions & 18 deletions images/win/scripts/Installers/Validate-PostgreSQL.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions images/win/scripts/Installers/Validate-PowershellCore.ps1

This file was deleted.

29 changes: 0 additions & 29 deletions images/win/scripts/Installers/Validate-Rust.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions images/win/scripts/Installers/Validate-Sbt.ps1

This file was deleted.

17 changes: 0 additions & 17 deletions images/win/scripts/Installers/Validate-ServiceFabricSDK.ps1

This file was deleted.

14 changes: 14 additions & 0 deletions images/win/scripts/Tests/Browsers.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,18 @@ Describe "Internet Explorer" {
"$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"
}
}
48 changes: 47 additions & 1 deletion images/win/scripts/Tests/Databases.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,55 @@ Describe "MongoDB" {
"$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" {
It "MySQL CLI" {
"mysql -V" | Should -ReturnZeroExitCode
}
}
}

Loading

0 comments on commit 0c4dca2

Please sign in to comment.