diff --git a/images/linux/scripts/helpers/Common.Helpers.psm1 b/images/linux/scripts/helpers/Common.Helpers.psm1 index 57d9e85a9..bcb9a250d 100644 --- a/images/linux/scripts/helpers/Common.Helpers.psm1 +++ b/images/linux/scripts/helpers/Common.Helpers.psm1 @@ -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) } \ No newline at end of file diff --git a/images/linux/scripts/installers/java-tools.sh b/images/linux/scripts/installers/java-tools.sh index a31af312a..b8dbd710f 100644 --- a/images/linux/scripts/installers/java-tools.sh +++ b/images/linux/scripts/installers/java-tools.sh @@ -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" diff --git a/images/linux/scripts/installers/mongodb.sh b/images/linux/scripts/installers/mongodb.sh index 5fd1b36a0..ad1403668 100644 --- a/images/linux/scripts/installers/mongodb.sh +++ b/images/linux/scripts/installers/mongodb.sh @@ -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" diff --git a/images/linux/scripts/installers/mysql.sh b/images/linux/scripts/installers/mysql.sh index 95483107e..8805afb73 100644 --- a/images/linux/scripts/installers/mysql.sh +++ b/images/linux/scripts/installers/mysql.sh @@ -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 diff --git a/images/linux/scripts/installers/postgresql.sh b/images/linux/scripts/installers/postgresql.sh index ddacdfb9e..4424adbf8 100644 --- a/images/linux/scripts/installers/postgresql.sh +++ b/images/linux/scripts/installers/postgresql.sh @@ -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" diff --git a/images/linux/scripts/tests/Databases.Tests.ps1 b/images/linux/scripts/tests/Databases.Tests.ps1 new file mode 100644 index 000000000..330123411 --- /dev/null +++ b/images/linux/scripts/tests/Databases.Tests.ps1 @@ -0,0 +1,30 @@ +Describe "MongoDB" { + It "" -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 + } +} \ No newline at end of file diff --git a/images/linux/scripts/tests/Java.Tests.ps1 b/images/linux/scripts/tests/Java.Tests.ps1 new file mode 100644 index 000000000..70a5d40d3 --- /dev/null +++ b/images/linux/scripts/tests/Java.Tests.ps1 @@ -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 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 "" -TestCases @( + @{ ToolName = "java" } + @{ ToolName = "javac" } + @{ ToolName = "mvn" } + @{ ToolName = "ant" } + @{ ToolName = "gradle" } + ) { + "$ToolName -version" | Should -ReturnZeroExitCode + } + + It "Java " -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}.")) + } +} \ No newline at end of file