From df05e8c6cbaa2a5850f2c4349929b2392303c46b Mon Sep 17 00:00:00 2001 From: Darii Nurgaleev <50947177+Darleev@users.noreply.github.com> Date: Mon, 11 Jan 2021 13:30:51 +0700 Subject: [PATCH] [macOS] Pester tests fail on error (#2378) * [macOS] Fail Pester tests on error * return it back * [macOS] Pester tests fail on error * some tests were moved * appcenter cli moved * openssl separate describe * added new tests for java * moved stack from haskell * invoke tests to stack * xamarin added tests sources * mongo tests fix * ndk path * xamarin-android-ndk-tests removed * fix nitpicks * added new filename for XamarinNDK * AzCopy Describe change * added azcopy C correct. * android additional_tools tests * remove null elements from massive * added new lines for verification macos 10.13 * add Android Tests for mac, not for linux --- images/macos/helpers/Tests.Helpers.psm1 | 1 + images/macos/provision/core/azcopy.sh | 2 +- images/macos/provision/core/stack.sh | 4 +- .../provision/core/xamarin-android-ndk.sh | 2 +- images/macos/provision/utils/invoke-tests.sh | 1 + images/macos/tests/Android.Tests.ps1 | 40 +----- images/macos/tests/Common.Tests.ps1 | 131 +++++++++--------- images/macos/tests/Java.Tests.ps1 | 24 ++++ images/macos/tests/XamarinNDK.Tests.ps1 | 32 +++++ 9 files changed, 135 insertions(+), 102 deletions(-) create mode 100644 images/macos/tests/XamarinNDK.Tests.ps1 diff --git a/images/macos/helpers/Tests.Helpers.psm1 b/images/macos/helpers/Tests.Helpers.psm1 index 791b90f0a..718933e5d 100644 --- a/images/macos/helpers/Tests.Helpers.psm1 +++ b/images/macos/helpers/Tests.Helpers.psm1 @@ -115,5 +115,6 @@ function Invoke-PesterTests { # Fail in case if no tests are run if (-not ($results -and ($results.FailedCount -eq 0) -and ($results.PassedCount -gt 0))) { $results + throw "Test run has failed" } } \ No newline at end of file diff --git a/images/macos/provision/core/azcopy.sh b/images/macos/provision/core/azcopy.sh index 96794aa9a..b491f08ee 100755 --- a/images/macos/provision/core/azcopy.sh +++ b/images/macos/provision/core/azcopy.sh @@ -14,4 +14,4 @@ chmod +x "/usr/local/bin/azcopy" echo "Done, cleaning up" rm -rf azcopy* -invoke_tests "Common" "Azcopy" \ No newline at end of file +invoke_tests "Common" "AzCopy" \ No newline at end of file diff --git a/images/macos/provision/core/stack.sh b/images/macos/provision/core/stack.sh index a642d985c..8c30a2014 100644 --- a/images/macos/provision/core/stack.sh +++ b/images/macos/provision/core/stack.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -o pipefail - +source ~/utils/invoke-tests.sh source ~/utils/utils.sh echo "Get the latest Stack version..." @@ -22,3 +22,5 @@ tar -xzf $StackArchive -C $DestinationPath --strip 1 touch $StackToolcachePath/x64.complete echo "export PATH="\$PATH":$DestinationPath" >> "$HOME/.bashrc" + +invoke_tests "Common" "Stack" diff --git a/images/macos/provision/core/xamarin-android-ndk.sh b/images/macos/provision/core/xamarin-android-ndk.sh index d5b23ebb0..adb8900de 100644 --- a/images/macos/provision/core/xamarin-android-ndk.sh +++ b/images/macos/provision/core/xamarin-android-ndk.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -o pipefail - +source ~/utils/invoke-tests.sh source ~/utils/utils.sh ANDROID_HOME=$HOME/Library/Android/sdk diff --git a/images/macos/provision/utils/invoke-tests.sh b/images/macos/provision/utils/invoke-tests.sh index 11474843c..b2425a8f5 100644 --- a/images/macos/provision/utils/invoke-tests.sh +++ b/images/macos/provision/utils/invoke-tests.sh @@ -4,6 +4,7 @@ invoke_tests() { local TEST_FILE="$1" local TEST_NAME="$2" + source $HOME/.bashrc pwsh -Command "Import-Module '$HOME/image-generation/helpers/Tests.Helpers.psm1' -DisableNameChecking Invoke-PesterTests -TestFile \"$TEST_FILE\" -TestName \"$TEST_NAME\"" } diff --git a/images/macos/tests/Android.Tests.ps1 b/images/macos/tests/Android.Tests.ps1 index d22feb2c0..5aadd3dc6 100644 --- a/images/macos/tests/Android.Tests.ps1 +++ b/images/macos/tests/Android.Tests.ps1 @@ -5,7 +5,6 @@ Import-Module "$PSScriptRoot/../software-report/SoftwareReport.Android.psm1" $os = Get-OSVersion Describe "Android" { - $androidNdkToolchains = @("mips64el-linux-android-4.9", "mipsel-linux-android-4.9") $androidSdkManagerPackages = Get-AndroidPackages [int]$platformMinVersion = Get-ToolsetValue "android.platform_min_version" [version]$buildToolsMinVersion = Get-ToolsetValue "android.build_tools_min_version" @@ -31,6 +30,9 @@ Describe "Android" { (Get-ToolsetValue "android.additional-tools") ) | ForEach-Object { $_ } + # Remove empty strings from array to avoid possible issues + $androidPackages = $androidPackages | Where-Object {$_} + BeforeAll { $ANDROID_SDK_DIR = Join-Path $env:HOME "Library" "Android" "sdk" @@ -48,7 +50,6 @@ Describe "Android" { } } - Context "Packages" { $testCases = $androidPackages | ForEach-Object { @{ PackageName = $_ } } @@ -58,41 +59,8 @@ Describe "Android" { } } - Context "NDK toolchains" -Skip:($os.IsBigSur) { - $testCases = $androidNdkToolchains | ForEach-Object { @{AndroidNdkToolchain = $_} } - - It "" -TestCases $testCases { - param ([string] $AndroidNdkToolchain) - - $toolchainPath = Join-Path $ANDROID_SDK_DIR "ndk-bundle" "toolchains" $AndroidNdkToolchain - $toolchainPath | Should -Exist - } - } - - Context "Legacy NDK versions" -Skip:($os.IsBigSur) { - It "Android NDK version r18b is installed" { - $ndk18BundlePath = Join-Path $ANDROID_SDK_DIR "ndk" "18.1.5063045" "source.properties" - $rawContent = Get-Content $ndk18BundlePath -Raw - $rawContent | Should -BeLikeExactly "*Revision = 18.*" - } - } - It "HAXM is installed" { $haxmPath = Join-Path $ANDROID_SDK_DIR "extras" "intel" "Hardware_Accelerated_Execution_Manager" "silent_install.sh" "$haxmPath -v" | Should -ReturnZeroExitCode } -} - -Describe "Gradle" { - It "Gradle is installed" { - "gradle --version" | Should -ReturnZeroExitCode - } - - It "Gradle is installed to /usr/local/bin" { - (Get-Command "gradle").Path | Should -BeExactly "/usr/local/bin/gradle" - } - - It "Gradle is compatible with init.d plugins" { - "cd /tmp && gradle tasks" | Should -ReturnZeroExitCode - } -} +} \ No newline at end of file diff --git a/images/macos/tests/Common.Tests.ps1 b/images/macos/tests/Common.Tests.ps1 index bf001a45c..6d47c4711 100644 --- a/images/macos/tests/Common.Tests.ps1 +++ b/images/macos/tests/Common.Tests.ps1 @@ -174,31 +174,6 @@ Describe "Common utilities" { "bundler --version" | Should -ReturnZeroExitCode } - It "Maven" { - "mvn --version" | Should -ReturnZeroExitCode - } - - It "App Center CLI" { - "appcenter --version" | Should -ReturnZeroExitCode - } - - It "Azure CLI" { - "az -v" | Should -ReturnZeroExitCode - } - - Describe "AWS" { - It "AWS CLI" { - "aws --version" | Should -ReturnZeroExitCode - } - It "AWS SAM CLI" { - "sam --version" | Should -ReturnZeroExitCode - } - - It "AWS Session Manager CLI" { - "session-manager-plugin --version" | Should -ReturnZeroExitCode - } - } - Context "Nomad" -Skip:($os.IsBigSur) { It "Nomad CLI" { $result = Get-CommandResult "gem list" @@ -209,13 +184,6 @@ Describe "Common utilities" { "ipa --version" | Should -ReturnZeroExitCode } } - Describe "Miniconda" { - It "Conda" { - Get-EnvironmentVariable "CONDA" | Should -Not -BeNullOrEmpty - $condaBinPath = Join-Path $env:CONDA "bin" "conda" - "$condaBinPath --version" | Should -ReturnZeroExitCode - } - } It "Fastlane" { "fastlane --version" | Should -ReturnZeroExitCode @@ -225,29 +193,6 @@ Describe "Common utilities" { "xcpretty --version" | Should -ReturnZeroExitCode } - Describe "Mongo" { - It "mongodb" { - "mongo --version" | Should -ReturnZeroExitCode - "mongod --version"| Should -ReturnZeroExitCode - } - } - - Describe "OpenSSL" { - It "OpenSSL is available" { - "openssl version" | Should -ReturnZeroExitCode - } - - It "OpenSSL 1.1 path exists" { - $openSSLpath = "/usr/local/opt/openssl@1.1" - $openSSLpath | Should -Exist - } - - It "Default OpenSSL version is 1.1" { - $commandResult = Get-CommandResult "openssl version" - $commandResult.Output | Should -Match "OpenSSL 1.1" - } - } - It "PostgreSQL-Client" { "psql --version" | Should -ReturnZeroExitCode } @@ -256,10 +201,6 @@ Describe "Common utilities" { "pg_config --version" | Should -ReturnZeroExitCode } - It "Azcopy" { - "azcopy --version" | Should -ReturnZeroExitCode - } - It "PHP" { Get-WhichTool "php" | Should -Not -BeLike "/usr/bin/php*" "php --version" | Should -ReturnZeroExitCode @@ -314,10 +255,6 @@ Describe "Haskell" -Skip:($os.IsHighSierra) { It "Cabal" { "cabal --version" | Should -ReturnZeroExitCode } - - It "Stack" { - "stack --version" | Should -ReturnZeroExitCode - } } Describe "GCC" -Skip:($os.IsHighSierra) { @@ -369,4 +306,72 @@ Describe "Visual Studio For Mac" { $vsPath | Should -Exist $vstoolPath | Should -Exist } +} + +Describe "AWS" { + It "AWS CLI" { + "aws --version" | Should -ReturnZeroExitCode + } + It "AWS SAM CLI" { + "sam --version" | Should -ReturnZeroExitCode + } + + It "AWS Session Manager CLI" { + "session-manager-plugin --version" | Should -ReturnZeroExitCode + } +} + +Describe "AzCopy" { + It "AzCopy" { + "azcopy --version" | Should -ReturnZeroExitCode + } +} + +Describe "AzureCLI" { + It "Azure CLI" { + "az -v" | Should -ReturnZeroExitCode + } +} + +Describe "Miniconda" { + It "Conda" { + Get-EnvironmentVariable "CONDA" | Should -Not -BeNullOrEmpty + $condaBinPath = Join-Path $env:CONDA "bin" "conda" + "$condaBinPath --version" | Should -ReturnZeroExitCode + } +} + +Describe "AppCenterCLI" { + It "App Center CLI" { + "appcenter --version" | Should -ReturnZeroExitCode + } +} + +Describe "OpenSSL" { + It "OpenSSL is available" { + "openssl version" | Should -ReturnZeroExitCode + } + + It "OpenSSL 1.1 path exists" { + $openSSLpath = "/usr/local/opt/openssl@1.1" + $openSSLpath | Should -Exist + } + + It "Default OpenSSL version is 1.1" { + $commandResult = Get-CommandResult "openssl version" + $commandResult.Output | Should -Match "OpenSSL 1.1" + } +} + +Describe "Stack" -Skip:($os.IsHighSierra) { + It "Stack" { + "stack --version" | Should -ReturnZeroExitCode + } +} + +Describe "Mongo" { + It "mongodb" { + "mongo --version" | Should -ReturnZeroExitCode + "mongod --version"| Should -ReturnZeroExitCode + } } \ No newline at end of file diff --git a/images/macos/tests/Java.Tests.ps1 b/images/macos/tests/Java.Tests.ps1 index 3ece545f4..1b81e2fb0 100644 --- a/images/macos/tests/Java.Tests.ps1 +++ b/images/macos/tests/Java.Tests.ps1 @@ -57,4 +57,28 @@ Describe "Java" { } } } + + Context "Maven" { + Describe "Maven" { + It "Maven" { + "mvn --version" | Should -ReturnZeroExitCode + } + } + } + + Context "Gradle" { + Describe "Gradle" { + It "Gradle is installed" { + "gradle --version" | Should -ReturnZeroExitCode + } + + It "Gradle is installed to /usr/local/bin" { + (Get-Command "gradle").Path | Should -BeExactly "/usr/local/bin/gradle" + } + + It "Gradle is compatible with init.d plugins" { + "cd /tmp && gradle tasks" | Should -ReturnZeroExitCode + } + } + } } \ No newline at end of file diff --git a/images/macos/tests/XamarinNDK.Tests.ps1 b/images/macos/tests/XamarinNDK.Tests.ps1 new file mode 100644 index 000000000..3495004ff --- /dev/null +++ b/images/macos/tests/XamarinNDK.Tests.ps1 @@ -0,0 +1,32 @@ + +Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" +Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" +Import-Module "$PSScriptRoot/../software-report/SoftwareReport.Android.psm1" + +$os = Get-OSVersion + +Describe "Xamarin NDK" { + BeforeAll { + $androidNdkToolchains = @("mips64el-linux-android-4.9", "mipsel-linux-android-4.9") + $ANDROID_SDK_DIR = Join-Path $env:HOME "Library" "Android" "sdk" + } + + Context "Xamarin NDK toolchains" -Skip:($os.IsBigSur) { + $testCases = $androidNdkToolchains | ForEach-Object { @{AndroidNdkToolchain = $_} } + + It "" -TestCases $testCases { + param ([string] $AndroidNdkToolchain) + + $toolchainPath = Join-Path $ANDROID_SDK_DIR "ndk-bundle" "toolchains" $AndroidNdkToolchain + $toolchainPath | Should -Exist + } + } + + Context "Xamarin Legacy NDK versions" -Skip:($os.IsBigSur) { + It "Android NDK version r18b is installed" { + $ndk18BundlePath = Join-Path $ANDROID_SDK_DIR "ndk" "18.1.5063045" "source.properties" + $rawContent = Get-Content $ndk18BundlePath -Raw + $rawContent | Should -BeLikeExactly "*Revision = 18.*" + } + } +} \ No newline at end of file