mirror of
https://github.com/actions/runner-images.git
synced 2025-12-10 19:16:48 +00:00
Databases and java pester tests (#2338)
* added mongodb postgres java tests * fixed 1.7 and 12 Java on Ubuntu 20 * several improvments * removed update-environment function * add etc-environment import * removed sourcing invoke-tests Co-authored-by: Leonid Lapshin <originalnoe-nazvanie@yandex.ru>
This commit is contained in:
@@ -54,4 +54,8 @@ function Get-AndroidPackages {
|
||||
$androidSDKManagerPath = "/usr/local/lib/android/sdk/tools/bin/sdkmanager"
|
||||
$androidPackages = & $androidSDKManagerPath --list --verbose
|
||||
return $androidPackages
|
||||
}
|
||||
|
||||
function Get-EnvironmentVariable($variable) {
|
||||
return [System.Environment]::GetEnvironmentVariable($variable)
|
||||
}
|
||||
@@ -5,15 +5,7 @@
|
||||
################################################################################
|
||||
|
||||
source $HELPER_SCRIPTS/os.sh
|
||||
|
||||
function javaTool {
|
||||
if [[ "$2" =~ ([1]{0,1}.)?$DEFAULT_JDK_VERSION.* ]]; then
|
||||
echo "$1 $2 is equal to default one $DEFAULT_JDK_VERSION"
|
||||
else
|
||||
echo "$1 $2 is not equal to default one $DEFAULT_JDK_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Install GPG Key for Adopt Open JDK. See https://adoptopenjdk.net/installation.html
|
||||
wget -qO - "https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public" | apt-key add -
|
||||
@@ -86,16 +78,5 @@ rm gradleLatest.zip
|
||||
ln -s /usr/share/gradle-"${gradleVersion}"/bin/gradle /usr/bin/gradle
|
||||
echo "GRADLE_HOME=/usr/share/gradle" | tee -a /etc/environment
|
||||
|
||||
# Run tests to determine that the software installed as expected
|
||||
echo "Testing to make sure that script performed as expected, and basic scenarios work"
|
||||
for cmd in gradle java javac mvn ant; do
|
||||
if ! command -v $cmd; then
|
||||
echo "$cmd was not installed or found on path"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
javaVersion=$(java -version |& head -n 1 | cut -d\" -f 2)
|
||||
javaTool "Java" $javaVersion
|
||||
javacVersion=$(javac -version |& cut -d" " -f2)
|
||||
javaTool "Javac" $javacVersion
|
||||
reloadEtcEnvironment
|
||||
invoke_tests "Java"
|
||||
|
||||
@@ -14,9 +14,4 @@ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $version/mong
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y mongodb-org
|
||||
|
||||
# Validate the installation
|
||||
echo "Validate the installation"
|
||||
if ! command -v mongod; then
|
||||
echo "mongodb was not installed"
|
||||
exit 1
|
||||
fi
|
||||
invoke_tests "Databases" "MongoDB"
|
||||
|
||||
@@ -33,17 +33,6 @@ apt-get install -y mysql-server
|
||||
#Install MySQL Dev tools
|
||||
apt install libmysqlclient-dev -y
|
||||
|
||||
# Run tests to determine that the software installed as expected
|
||||
echo "Testing to make sure that script performed as expected, and basic scenarios work"
|
||||
if ! command -v mysql; then
|
||||
echo "mysql was not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mysql -vvv -e 'CREATE DATABASE smoke_test' -uroot -proot
|
||||
mysql -vvv -e 'DROP DATABASE smoke_test' -uroot -proot
|
||||
set +e
|
||||
|
||||
# Disable mysql.service
|
||||
systemctl is-active --quiet mysql.service && systemctl stop mysql.service
|
||||
systemctl disable mysql.service
|
||||
|
||||
@@ -15,13 +15,8 @@ apt install postgresql postgresql-client
|
||||
echo "Install libpq-dev"
|
||||
apt-get install libpq-dev
|
||||
|
||||
#Verify that PostgreSQL is ready for accept incoming connections.
|
||||
# exit codes:
|
||||
# ready - 0
|
||||
# reject - 1
|
||||
# connection timeout - 2
|
||||
pg_isready
|
||||
|
||||
# Disable postgresql.service
|
||||
systemctl is-active --quiet postgresql.service && systemctl stop postgresql.service
|
||||
systemctl disable postgresql.service
|
||||
|
||||
invoke_tests "Databases" "PostgreSQL"
|
||||
|
||||
30
images/linux/scripts/tests/Databases.Tests.ps1
Normal file
30
images/linux/scripts/tests/Databases.Tests.ps1
Normal file
@@ -0,0 +1,30 @@
|
||||
Describe "MongoDB" {
|
||||
It "<ToolName>" -TestCases @(
|
||||
@{ ToolName = "mongo" }
|
||||
@{ ToolName = "mongod" }
|
||||
) {
|
||||
"$ToolName --version" | Should -ReturnZeroExitCode
|
||||
}
|
||||
}
|
||||
|
||||
Describe "PostgreSQL" {
|
||||
|
||||
It "PostgreSQL Service" {
|
||||
"sudo systemctl start postgresql" | Should -ReturnZeroExitCode
|
||||
(Get-CommandResult "pg_isready").Output | Should -Be "/var/run/postgresql:5432 - accepting connections"
|
||||
"sudo systemctl stop postgresql" | Should -ReturnZeroExitCode
|
||||
}
|
||||
}
|
||||
|
||||
Describe "MySQL" {
|
||||
It "MySQL CLI" {
|
||||
"mysql -V" | Should -ReturnZeroExitCode
|
||||
}
|
||||
|
||||
It "MySQL Service" {
|
||||
"sudo systemctl start mysql" | Should -ReturnZeroExitCode
|
||||
"sudo mysql -vvv -e 'CREATE DATABASE smoke_test' -uroot -proot" | Should -ReturnZeroExitCode
|
||||
"sudo mysql -vvv -e 'DROP DATABASE smoke_test' -uroot -proot" | Should -ReturnZeroExitCode
|
||||
"sudo systemctl stop mysql" | Should -ReturnZeroExitCode
|
||||
}
|
||||
}
|
||||
53
images/linux/scripts/tests/Java.Tests.ps1
Normal file
53
images/linux/scripts/tests/Java.Tests.ps1
Normal file
@@ -0,0 +1,53 @@
|
||||
Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" -DisableNameChecking
|
||||
|
||||
Describe "Java" {
|
||||
|
||||
if (Test-IsUbuntu20) {
|
||||
$defaultJavaVersion = "11"
|
||||
$javaTestCases = @(
|
||||
@{ Version = "1.8" }
|
||||
@{ Version = "11" }
|
||||
)
|
||||
}
|
||||
|
||||
if ((Test-IsUbuntu16) -or (Test-IsUbuntu18)) {
|
||||
$defaultJavaVersion = "8"
|
||||
$javaTestCases = @(
|
||||
@{ Version = "1.7" }
|
||||
@{ Version = "1.8" }
|
||||
@{ Version = "11" }
|
||||
@{ Version = "12" }
|
||||
)
|
||||
}
|
||||
|
||||
It "Java <DefaultJavaVersion> is default" -TestCases @{ defaultJavaVersion = $defaultJavaVersion } {
|
||||
$actualJavaPath = Get-EnvironmentVariable "JAVA_HOME"
|
||||
$expectedJavaPath = Get-EnvironmentVariable "JAVA_HOME_${defaultJavaVersion}_X64"
|
||||
|
||||
$actualJavaPath | Should -Not -BeNullOrEmpty
|
||||
$expectedJavaPath | Should -Not -BeNullOrEmpty
|
||||
$actualJavaPath | Should -Be $expectedJavaPath
|
||||
}
|
||||
|
||||
It "<ToolName>" -TestCases @(
|
||||
@{ ToolName = "java" }
|
||||
@{ ToolName = "javac" }
|
||||
@{ ToolName = "mvn" }
|
||||
@{ ToolName = "ant" }
|
||||
@{ ToolName = "gradle" }
|
||||
) {
|
||||
"$ToolName -version" | Should -ReturnZeroExitCode
|
||||
}
|
||||
|
||||
It "Java <Version>" -TestCases $javaTestCases {
|
||||
$versionNumber = $version.Split(".") | Select-Object -Last 1
|
||||
|
||||
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${versionNumber}_X64"
|
||||
$javaVariableValue | Should -Not -BeNullOrEmpty
|
||||
$javaPath = Join-Path $javaVariableValue "bin/java"
|
||||
|
||||
$result = Get-CommandResult "`"$javaPath`" -version"
|
||||
$result.ExitCode | Should -Be 0
|
||||
$result.Output | Should -Match ([regex]::Escape("openjdk version `"${Version}."))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user