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:
Leonid Lapshin
2020-12-30 18:04:55 +03:00
committed by GitHub
parent 86adee10d0
commit 3753e7b923
7 changed files with 93 additions and 46 deletions

View File

@@ -54,4 +54,8 @@ function Get-AndroidPackages {
$androidSDKManagerPath = "/usr/local/lib/android/sdk/tools/bin/sdkmanager" $androidSDKManagerPath = "/usr/local/lib/android/sdk/tools/bin/sdkmanager"
$androidPackages = & $androidSDKManagerPath --list --verbose $androidPackages = & $androidSDKManagerPath --list --verbose
return $androidPackages return $androidPackages
}
function Get-EnvironmentVariable($variable) {
return [System.Environment]::GetEnvironmentVariable($variable)
} }

View File

@@ -5,15 +5,7 @@
################################################################################ ################################################################################
source $HELPER_SCRIPTS/os.sh source $HELPER_SCRIPTS/os.sh
source $HELPER_SCRIPTS/etc-environment.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
}
# Install GPG Key for Adopt Open JDK. See https://adoptopenjdk.net/installation.html # 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 - 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 ln -s /usr/share/gradle-"${gradleVersion}"/bin/gradle /usr/bin/gradle
echo "GRADLE_HOME=/usr/share/gradle" | tee -a /etc/environment echo "GRADLE_HOME=/usr/share/gradle" | tee -a /etc/environment
# Run tests to determine that the software installed as expected reloadEtcEnvironment
echo "Testing to make sure that script performed as expected, and basic scenarios work" invoke_tests "Java"
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

View File

@@ -14,9 +14,4 @@ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $version/mong
sudo apt-get update sudo apt-get update
sudo apt-get install -y mongodb-org sudo apt-get install -y mongodb-org
# Validate the installation invoke_tests "Databases" "MongoDB"
echo "Validate the installation"
if ! command -v mongod; then
echo "mongodb was not installed"
exit 1
fi

View File

@@ -33,17 +33,6 @@ apt-get install -y mysql-server
#Install MySQL Dev tools #Install MySQL Dev tools
apt install libmysqlclient-dev -y 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 # Disable mysql.service
systemctl is-active --quiet mysql.service && systemctl stop mysql.service systemctl is-active --quiet mysql.service && systemctl stop mysql.service
systemctl disable mysql.service systemctl disable mysql.service

View File

@@ -15,13 +15,8 @@ apt install postgresql postgresql-client
echo "Install libpq-dev" echo "Install libpq-dev"
apt-get 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 # Disable postgresql.service
systemctl is-active --quiet postgresql.service && systemctl stop postgresql.service systemctl is-active --quiet postgresql.service && systemctl stop postgresql.service
systemctl disable postgresql.service systemctl disable postgresql.service
invoke_tests "Databases" "PostgreSQL"

View 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
}
}

View 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}."))
}
}