diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index 26b6e9c74..496fe3c2f 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -173,12 +173,6 @@ "{{ template_dir }}/scripts/Installers/Validate-Docker.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-PowershellCore.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -275,12 +269,6 @@ "{{ template_dir }}/scripts/Installers/Validate-WDK.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-ServiceFabricSDK.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -522,12 +510,6 @@ "{{ template_dir }}/scripts/Installers/Install-MysqlCli.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-PostgreSQL.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -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":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index a345f29a6..53e06aca6 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -181,12 +181,6 @@ "{{ template_dir }}/scripts/Installers/Validate-Docker.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-PowershellCore.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -268,12 +262,6 @@ "{{ template_dir }}/scripts/Installers/Validate-WDK.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-ServiceFabricSDK.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -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":[ @@ -767,12 +743,6 @@ "{{ template_dir }}/scripts/Installers/Validate-Vcpkg.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-PostgreSQL.ps1" - ] - }, { "type": "powershell", "scripts":[ diff --git a/images/win/scripts/ImageHelpers/TestsHelpers.ps1 b/images/win/scripts/ImageHelpers/TestsHelpers.ps1 index f2c6e437c..7b5f012ba 100644 --- a/images/win/scripts/ImageHelpers/TestsHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/TestsHelpers.ps1 @@ -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 diff --git a/images/win/scripts/Installers/Install-PostgreSQL.ps1 b/images/win/scripts/Installers/Install-PostgreSQL.ps1 index 11f5476d4..7d46d43ec 100644 --- a/images/win/scripts/Installers/Install-PostgreSQL.ps1 +++ b/images/win/scripts/Installers/Install-PostgreSQL.ps1 @@ -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" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-PowershellCore.ps1 b/images/win/scripts/Installers/Install-PowershellCore.ps1 index 77e446583..1e620c74b 100644 --- a/images/win/scripts/Installers/Install-PowershellCore.ps1 +++ b/images/win/scripts/Installers/Install-PowershellCore.ps1 @@ -4,3 +4,5 @@ ################################################################################ Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet" + +Invoke-PesterTests -TestFile "Tools" -TestName "PowerShell Core" diff --git a/images/win/scripts/Installers/Install-Rust.ps1 b/images/win/scripts/Installers/Install-Rust.ps1 index bbb259a0e..35e16dcd9 100644 --- a/images/win/scripts/Installers/Install-Rust.ps1 +++ b/images/win/scripts/Installers/Install-Rust.ps1 @@ -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/# @@ -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" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Sbt.ps1 b/images/win/scripts/Installers/Install-Sbt.ps1 index bc0e95a20..fc8b6a509 100644 --- a/images/win/scripts/Installers/Install-Sbt.ps1 +++ b/images/win/scripts/Installers/Install-Sbt.ps1 @@ -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" diff --git a/images/win/scripts/Installers/Install-Selenium.ps1 b/images/win/scripts/Installers/Install-Selenium.ps1 index 720e28039..d49ad082d 100644 --- a/images/win/scripts/Installers/Install-Selenium.ps1 +++ b/images/win/scripts/Installers/Install-Selenium.ps1 @@ -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" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-ServiceFabricSDK.ps1 b/images/win/scripts/Installers/Install-ServiceFabricSDK.ps1 index 25a0429db..a36787094 100644 --- a/images/win/scripts/Installers/Install-ServiceFabricSDK.ps1 +++ b/images/win/scripts/Installers/Install-ServiceFabricSDK.ps1 @@ -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" diff --git a/images/win/scripts/Installers/Validate-PostgreSQL.ps1 b/images/win/scripts/Installers/Validate-PostgreSQL.ps1 deleted file mode 100644 index 739a5fe59..000000000 --- a/images/win/scripts/Installers/Validate-PostgreSQL.ps1 +++ /dev/null @@ -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 diff --git a/images/win/scripts/Installers/Validate-PowershellCore.ps1 b/images/win/scripts/Installers/Validate-PowershellCore.ps1 deleted file mode 100644 index b21a4064d..000000000 --- a/images/win/scripts/Installers/Validate-PowershellCore.ps1 +++ /dev/null @@ -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 -} - diff --git a/images/win/scripts/Installers/Validate-Rust.ps1 b/images/win/scripts/Installers/Validate-Rust.ps1 deleted file mode 100644 index 88968a21c..000000000 --- a/images/win/scripts/Installers/Validate-Rust.ps1 +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/images/win/scripts/Installers/Validate-Sbt.ps1 b/images/win/scripts/Installers/Validate-Sbt.ps1 deleted file mode 100644 index 16944722c..000000000 --- a/images/win/scripts/Installers/Validate-Sbt.ps1 +++ /dev/null @@ -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 -} - diff --git a/images/win/scripts/Installers/Validate-ServiceFabricSDK.ps1 b/images/win/scripts/Installers/Validate-ServiceFabricSDK.ps1 deleted file mode 100644 index 7984335eb..000000000 --- a/images/win/scripts/Installers/Validate-ServiceFabricSDK.ps1 +++ /dev/null @@ -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" -} - diff --git a/images/win/scripts/Tests/Browsers.Tests.ps1 b/images/win/scripts/Tests/Browsers.Tests.ps1 index 5f687090b..7dbce4585 100644 --- a/images/win/scripts/Tests/Browsers.Tests.ps1 +++ b/images/win/scripts/Tests/Browsers.Tests.ps1 @@ -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" + } } \ No newline at end of file diff --git a/images/win/scripts/Tests/Databases.Tests.ps1 b/images/win/scripts/Tests/Databases.Tests.ps1 index ab9c908ed..bf478c52a 100644 --- a/images/win/scripts/Tests/Databases.Tests.ps1 +++ b/images/win/scripts/Tests/Databases.Tests.ps1 @@ -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 " environment variable exists" -TestCases $psqlTests { + Get-EnvironmentVariable $envVar | Should -Not -BeNullOrEmpty + } + } + + Context "Path" { + It " 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 " service is stopped" -TestCases $psqlServiceTests { + $Status | Should -Be "Stopped" + } + + It " service is disabled" -TestCases $psqlServiceTests { + $StartType | Should -Be "Disabled" + } + } +} + Describe "MySQL" { It "MySQL CLI" { "mysql -V" | Should -ReturnZeroExitCode - } + } } diff --git a/images/win/scripts/Tests/Rust.Tests.ps1 b/images/win/scripts/Tests/Rust.Tests.ps1 new file mode 100644 index 000000000..49e0c694f --- /dev/null +++ b/images/win/scripts/Tests/Rust.Tests.ps1 @@ -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 " environment variable does not exist" -TestCases $rustEnvNotExists { + [Environment]::GetEnvironmentVariables("Machine").ContainsKey($envVar) | Should -BeFalse + } + + It " is installed to the '' folder" -TestCases $rustTools { + "$ToolName --version" | Should -ReturnZeroExitCode + $binPath | Should -Exist + } +} \ No newline at end of file diff --git a/images/win/scripts/Tests/Tools.Tests.ps1 b/images/win/scripts/Tests/Tools.Tests.ps1 index d9ca3906c..fda74d4bb 100644 --- a/images/win/scripts/Tests/Tools.Tests.ps1 +++ b/images/win/scripts/Tests/Tools.Tests.ps1 @@ -133,4 +133,26 @@ Describe "Perl" { It "Perl" { "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 + } } \ No newline at end of file