From f5b6afebd0b19cfcb58fbdd4ca881d78698fec7a Mon Sep 17 00:00:00 2001 From: Darii Nurgaleev <50947177+Darleev@users.noreply.github.com> Date: Fri, 29 Jan 2021 16:37:48 +0700 Subject: [PATCH] [macOS] move Pester tests to separate files/contexts/describes (#2573) * [macOS] Fail Pester tests on error * return it back * added all files for testing * common utils path changed * linux scripts shouldn't be touched --- images/macos/provision/core/audiodevice.sh | 2 +- images/macos/provision/core/commonutils.sh | 4 +- images/macos/provision/core/git.sh | 2 +- images/macos/provision/core/openssl.sh | 2 +- images/macos/tests/BasicTools.Tests.ps1 | 163 +++++++++++++++++ images/macos/tests/Common.Tests.ps1 | 197 --------------------- images/macos/tests/Git.Tests.ps1 | 13 ++ images/macos/tests/Node.Tests.ps1 | 14 ++ images/macos/tests/OpenSSL.Tests.ps1 | 21 +++ images/macos/tests/Powershell.Tests.ps1 | 12 +- images/macos/tests/System.Tests.ps1 | 38 ++++ 11 files changed, 264 insertions(+), 204 deletions(-) create mode 100644 images/macos/tests/BasicTools.Tests.ps1 create mode 100644 images/macos/tests/Git.Tests.ps1 create mode 100644 images/macos/tests/OpenSSL.Tests.ps1 create mode 100644 images/macos/tests/System.Tests.ps1 diff --git a/images/macos/provision/core/audiodevice.sh b/images/macos/provision/core/audiodevice.sh index a05deeec..bf9f0f32 100644 --- a/images/macos/provision/core/audiodevice.sh +++ b/images/macos/provision/core/audiodevice.sh @@ -14,4 +14,4 @@ echo "set Soundflower (2ch) as input/output device" SwitchAudioSource -s "Soundflower (2ch)" -t input SwitchAudioSource -s "Soundflower (2ch)" -t output -invoke_tests "Common" "Audio Device" +invoke_tests "System" "Audio Device" diff --git a/images/macos/provision/core/commonutils.sh b/images/macos/provision/core/commonutils.sh index 0d23ab8d..a13f6a7d 100644 --- a/images/macos/provision/core/commonutils.sh +++ b/images/macos/provision/core/commonutils.sh @@ -22,5 +22,5 @@ fi # Invoke bazel to download bazel version via bazelisk bazel -# Invoke tests for all common tools -invoke_tests "Common" "CommonUtils" +# Invoke tests for all basic tools +invoke_tests "BasicTools" diff --git a/images/macos/provision/core/git.sh b/images/macos/provision/core/git.sh index 582b9e3a..7443e477 100644 --- a/images/macos/provision/core/git.sh +++ b/images/macos/provision/core/git.sh @@ -31,4 +31,4 @@ git config --global advice.detachedHead false git config --global advice.amWorkDir false git config --global advice.rmHints false -invoke_tests "Common" "Git" +invoke_tests "Git" diff --git a/images/macos/provision/core/openssl.sh b/images/macos/provision/core/openssl.sh index 0e735ddb..5c28fd80 100755 --- a/images/macos/provision/core/openssl.sh +++ b/images/macos/provision/core/openssl.sh @@ -10,4 +10,4 @@ brew_smart_install "openssl@1.1" # Symlink brew openssl@1.1 to `/usr/local/bin` as Homebrew refuses ln -sf $(brew --prefix openssl@1.1)/bin/openssl /usr/local/bin/openssl -invoke_tests "Common" "OpenSSL" +invoke_tests "OpenSSL" diff --git a/images/macos/tests/BasicTools.Tests.ps1 b/images/macos/tests/BasicTools.Tests.ps1 new file mode 100644 index 00000000..01ff9def --- /dev/null +++ b/images/macos/tests/BasicTools.Tests.ps1 @@ -0,0 +1,163 @@ +$os = Get-OSVersion + +Describe "Carthage" { + It "Carthage" { + "carthage version" | Should -ReturnZeroExitCode + } +} + +Describe "cmake" { + It "cmake" { + "cmake --version" | Should -ReturnZeroExitCode + } +} + +Describe "Subversion" { + It "Subversion" { + "svn --version" | Should -ReturnZeroExitCode + } +} + +Describe "Go" { + It "Go" { + "go version" | Should -ReturnZeroExitCode + } +} + +Describe "GnuPG" { + It "GnuPG" { + "gpg --version" | Should -ReturnZeroExitCode + } +} + +Describe "Clang/LLVM" { + It "Clang/LLVM is installed" { + "$(brew --prefix llvm)/bin/clang --version" | Should -ReturnZeroExitCode + } +} + +Describe "zstd" { + It "zstd" { + "zstd --version" | Should -ReturnZeroExitCode + } +} + +Describe "Packer" { + It "Packer" { + "packer --version" | Should -ReturnZeroExitCode + } +} + +Describe "Perl" { + It "Perl" { + "perl -e 'print substr($^V,1)'" | Should -ReturnZeroExitCode + } +} + +Describe "Helm" { + It "Helm" { + "helm version --short" | Should -ReturnZeroExitCode + } +} + +Describe "bazelisk" { + It "bazelisk" { + "bazelisk version" | Should -ReturnZeroExitCode + } +} + +Describe "Github CLI" { + It "GitHub CLI" { + "gh --version" | Should -ReturnZeroExitCode + } +} + +Describe "7-Zip" { + It "7-Zip" { + "7z i" | Should -ReturnZeroExitCode + } +} + +Describe "Apache Ant" { + It "Apache Ant" { + "ant -version" | Should -ReturnZeroExitCode + } +} + +Describe "Aria2" { + It "Aria2" { + "aria2c --version" | Should -ReturnZeroExitCode + } +} + +Describe "GNU Tar" { + It "GNU Tar" { + "gtar --version" | Should -ReturnZeroExitCode + } +} + +Describe "bazel" { + It "bazel" { + "bazel --version" | Should -ReturnZeroExitCode + } +} + +Describe "Aliyun CLI" { + It "Aliyun CLI" { + "aliyun --version" | Should -ReturnZeroExitCode + } +} + +Describe "Julia" { + It "Julia" { + "julia --version" | Should -ReturnZeroExitCode + } +} + +Describe "jq" { + It "jq" { + "jq --version" | Should -ReturnZeroExitCode + } +} + +Describe "curl" { + It "curl" { + "curl --version" | Should -ReturnZeroExitCode + } +} + +Describe "wget" { + It "wget" { + "wget --version" | Should -ReturnZeroExitCode + } +} + +Describe "vagrant" -Skip:($os.IsBigSur) { + It "vagrant" { + "vagrant --version" | Should -ReturnZeroExitCode + } +} + +Describe "virtualbox" -Skip:($os.IsBigSur) { + It "virtualbox" { + "vboxmanage -v" | Should -ReturnZeroExitCode + } +} + +Describe "xctool" -Skip:($os.IsBigSur) { + It "xctool" { + "xctool --version" | Should -ReturnZeroExitCode + } +} + +Describe "R" -Skip:($os.IsBigSur) { + It "R" { + "R --version" | Should -ReturnZeroExitCode + } +} + +Describe "Homebrew" { + It "Homebrew" { + "brew --version" | 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 565f30bf..2994573a 100644 --- a/images/macos/tests/Common.Tests.ps1 +++ b/images/macos/tests/Common.Tests.ps1 @@ -3,169 +3,12 @@ Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -DisableNameChecking $os = Get-OSVersion -Describe "Disk free space" { - It "Image has more than 10GB free space" { - # we should have at least 10 GB of free space on macOS images - # https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops#capabilities-and-limitations - $freeSpace = (Get-PSDrive "/").Free - $freeSpace | Should -BeGreaterOrEqual 10GB - } -} - -Describe "Certificate" { - It "Apple Worldwide Developer Relations Certification Authority[expired: 2030-02] is installed" { - $sha1Hash = "06EC06599F4ED0027CC58956B4D3AC1255114F35" - $certs = security find-certificate -a -c Worldwide -p -Z | Out-String - $certs | Should -Match $sha1Hash - } -} - -Describe "Git" { - It "git is installed" { - "git --version" | Should -ReturnZeroExitCode - } - - It "git lfs is installed" { - "git lfs version" | Should -ReturnZeroExitCode - } - - It "hub CLI is installed" { - "hub --version" | Should -ReturnZeroExitCode - } -} - -Describe "Audio device" -Skip:($os.IsHighSierra -or $os.IsBigSur) { - It "Sox is installed" { - "sox --version" | Should -ReturnZeroExitCode - } - - It "SwitchAudioSource is installed" { - "SwitchAudioSource -c" | Should -ReturnZeroExitCode - } - - It "Audio channel Soundflower (2ch)" { - SwitchAudioSource -c | Should -BeLikeExactly "Soundflower (2ch)" - } -} - -Describe "CommonUtils" { - It "Carthage" { - "carthage version" | Should -ReturnZeroExitCode - } - - It "cmake" { - "cmake --version" | Should -ReturnZeroExitCode - } - - It "Subversion" { - "svn --version" | Should -ReturnZeroExitCode - } - - It "Go" { - "go version" | Should -ReturnZeroExitCode - } - - It "GnuPG" { - "gpg --version" | Should -ReturnZeroExitCode - } - - It "Clang/LLVM is installed" { - "$(brew --prefix llvm)/bin/clang --version" | Should -ReturnZeroExitCode - } - - It "zstd" { - "zstd --version" | Should -ReturnZeroExitCode - } - - It "Packer" { - "packer --version" | Should -ReturnZeroExitCode - } - - It "Perl" { - "perl -e 'print substr($^V,1)'" | Should -ReturnZeroExitCode - } - - It "Helm" { - "helm version --short" | Should -ReturnZeroExitCode - } - - It "bazelisk" { - "bazelisk version" | Should -ReturnZeroExitCode - } - - It "GitHub CLI" { - "gh --version" | Should -ReturnZeroExitCode - } - - It "7-Zip" { - "7z i" | Should -ReturnZeroExitCode - } - - It "Apache Ant" { - "ant -version" | Should -ReturnZeroExitCode - } - - It "Aria2" { - "aria2c --version" | Should -ReturnZeroExitCode - } - - It "GNU Tar" { - "gtar --version" | Should -ReturnZeroExitCode - } - - It "bazel" { - "bazel --version" | Should -ReturnZeroExitCode - } - - It "Aliyun CLI" { - "aliyun --version" | Should -ReturnZeroExitCode - } - - It "Julia" { - "julia --version" | Should -ReturnZeroExitCode - } - - It "jq" { - "jq --version" | Should -ReturnZeroExitCode - } - - It "curl" { - "curl --version" | Should -ReturnZeroExitCode - } - - It "wget" { - "wget --version" | Should -ReturnZeroExitCode - } - - It "vagrant" -Skip:($os.IsBigSur) { - "vagrant --version" | Should -ReturnZeroExitCode - } - - It "virtualbox" -Skip:($os.IsBigSur) { - "vboxmanage -v" | Should -ReturnZeroExitCode - } - - It "xctool" -Skip:($os.IsBigSur) { - "xctool --version" | Should -ReturnZeroExitCode - } - - It "R" -Skip:($os.IsBigSur) { - "R --version" | Should -ReturnZeroExitCode - } -} - Describe ".NET" { It ".NET" { "dotnet --version" | Should -ReturnZeroExitCode } } -Describe "Homebrew" { - It "Homebrew" { - "brew --version" | Should -ReturnZeroExitCode - } -} - Describe "GCC" -Skip:($os.IsHighSierra) { $testCases = @("8", "9", "10") | ForEach-Object { @{Version = $_} } @@ -190,24 +33,12 @@ Describe "GCC" -Skip:($os.IsHighSierra) { } } -Describe "Screen Resolution" -Skip:($os.IsHighSierra) { - It "Screen Resolution" { - system_profiler SPDisplaysDataType | Select-String "Resolution" | Should -Match "1176 x 885" - } -} - Describe "vcpkg" -Skip:($os.IsHighSierra -or $os.IsMojave) { It "vcpkg" { "vcpkg version" | Should -ReturnZeroExitCode } } -Describe "Newman" -Skip:($os.IsHighSierra -or $os.IsMojave) { - It "Newman" { - "newman --version" | Should -ReturnZeroExitCode - } -} - Describe "AWS" { It "AWS CLI" { "aws --version" | Should -ReturnZeroExitCode @@ -227,12 +58,6 @@ Describe "AzCopy" { } } -Describe "AzureCLI" { - It "Azure CLI" { - "az -v" | Should -ReturnZeroExitCode - } -} - Describe "Miniconda" { It "Conda" { Get-EnvironmentVariable "CONDA" | Should -Not -BeNullOrEmpty @@ -241,28 +66,6 @@ Describe "Miniconda" { } } -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 diff --git a/images/macos/tests/Git.Tests.ps1 b/images/macos/tests/Git.Tests.ps1 new file mode 100644 index 00000000..4638c21f --- /dev/null +++ b/images/macos/tests/Git.Tests.ps1 @@ -0,0 +1,13 @@ +Describe "Git" { + It "git is installed" { + "git --version" | Should -ReturnZeroExitCode + } + + It "git lfs is installed" { + "git lfs version" | Should -ReturnZeroExitCode + } + + It "hub CLI is installed" { + "hub --version" | Should -ReturnZeroExitCode + } +} \ No newline at end of file diff --git a/images/macos/tests/Node.Tests.ps1 b/images/macos/tests/Node.Tests.ps1 index 667f17e9..d63d07f8 100644 --- a/images/macos/tests/Node.Tests.ps1 +++ b/images/macos/tests/Node.Tests.ps1 @@ -1,6 +1,8 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -DisableNameChecking +$os = Get-OSVersion + Describe "Node.js" { BeforeAll { $os = Get-OSVersion @@ -48,3 +50,15 @@ Describe "nvm" { } } } + +Describe "AppCenterCLI" { + It "App Center CLI" { + "appcenter --version" | Should -ReturnZeroExitCode + } +} + +Describe "Newman" -Skip:($os.IsHighSierra -or $os.IsMojave) { + It "Newman" { + "newman --version" | Should -ReturnZeroExitCode + } +} diff --git a/images/macos/tests/OpenSSL.Tests.ps1 b/images/macos/tests/OpenSSL.Tests.ps1 new file mode 100644 index 00000000..5abf9efe --- /dev/null +++ b/images/macos/tests/OpenSSL.Tests.ps1 @@ -0,0 +1,21 @@ +Describe "OpenSSL" { + Context "OpenSSL Version" { + It "OpenSSL is available" { + "openssl version" | Should -ReturnZeroExitCode + } + } + + Context "OpenSSL 1.1 Path Check" { + It "OpenSSL 1.1 path exists" { + $openSSLpath = "/usr/local/opt/openssl@1.1" + $openSSLpath | Should -Exist + } + } + + Context "OpenSSL 1.1 is default" { + It "Default OpenSSL version is 1.1" { + $commandResult = Get-CommandResult "openssl version" + $commandResult.Output | Should -Match "OpenSSL 1.1" + } + } +} \ No newline at end of file diff --git a/images/macos/tests/Powershell.Tests.ps1 b/images/macos/tests/Powershell.Tests.ps1 index 2be58e0a..b92ac6b2 100644 --- a/images/macos/tests/Powershell.Tests.ps1 +++ b/images/macos/tests/Powershell.Tests.ps1 @@ -2,8 +2,10 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -DisableNameChecking Describe "Powershell" { - It "Powershell is installed" { - "pwsh -v" | Should -ReturnZeroExitCode + Context "Powershell is installed" { + It "Powershell is installed" { + "pwsh -v" | Should -ReturnZeroExitCode + } } Context "Powershell Modules" { @@ -38,4 +40,10 @@ Describe "Powershell" { } } } + + Context "Azure CLI" { + It "Azure CLI" { + "az -v" | Should -ReturnZeroExitCode + } + } } \ No newline at end of file diff --git a/images/macos/tests/System.Tests.ps1 b/images/macos/tests/System.Tests.ps1 new file mode 100644 index 00000000..ea5e1375 --- /dev/null +++ b/images/macos/tests/System.Tests.ps1 @@ -0,0 +1,38 @@ +$os = Get-OSVersion + +Describe "Disk free space" { + It "Image has more than 10GB free space" { + # we should have at least 10 GB of free space on macOS images + # https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops#capabilities-and-limitations + $freeSpace = (Get-PSDrive "/").Free + $freeSpace | Should -BeGreaterOrEqual 10GB + } +} + +Describe "Certificate" { + It "Apple Worldwide Developer Relations Certification Authority[expired: 2030-02] is installed" { + $sha1Hash = "06EC06599F4ED0027CC58956B4D3AC1255114F35" + $certs = security find-certificate -a -c Worldwide -p -Z | Out-String + $certs | Should -Match $sha1Hash + } +} + +Describe "Audio device" -Skip:($os.IsHighSierra -or $os.IsBigSur) { + It "Sox is installed" { + "sox --version" | Should -ReturnZeroExitCode + } + + It "SwitchAudioSource is installed" { + "SwitchAudioSource -c" | Should -ReturnZeroExitCode + } + + It "Audio channel Soundflower (2ch)" { + SwitchAudioSource -c | Should -BeLikeExactly "Soundflower (2ch)" + } +} + +Describe "Screen Resolution" -Skip:($os.IsHighSierra) { + It "Screen Resolution" { + system_profiler SPDisplaysDataType | Select-String "Resolution" | Should -Match "1176 x 885" + } +}