From 1ce075fe93400af010bfc4517a646eea8d882591 Mon Sep 17 00:00:00 2001 From: Leonid Lapshin Date: Wed, 30 Dec 2020 13:50:21 +0300 Subject: [PATCH] [ubuntu] Pester tests for dotnet sdk, cmd tools and codeql (#2335) * dotnet cmd codeql tests * fixed dotnet tests, added codeql to toolset * changed codeql version to wildcard * removed unused import and a test call * tmp * lowercase file name * removed sourcing invoke-tests Co-authored-by: Leonid Lapshin --- images/linux/scripts/installers/basic.sh | 9 +----- .../linux/scripts/installers/codeql-bundle.sh | 3 -- .../scripts/installers/dotnetcore-sdk.sh | 2 ++ images/linux/scripts/tests/Apt.Tests.ps1 | 14 +++++++++ .../linux/scripts/tests/DotnetSDK.Tests.ps1 | 31 +++++++++++++++++++ images/linux/scripts/tests/Toolset.Tests.ps1 | 6 +++- images/linux/toolsets/toolset-1604.json | 8 +++++ images/linux/toolsets/toolset-1804.json | 8 +++++ images/linux/toolsets/toolset-2004.json | 8 +++++ 9 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 images/linux/scripts/tests/Apt.Tests.ps1 create mode 100644 images/linux/scripts/tests/DotnetSDK.Tests.ps1 diff --git a/images/linux/scripts/installers/basic.sh b/images/linux/scripts/installers/basic.sh index df9aae08f..49045cb7a 100644 --- a/images/linux/scripts/installers/basic.sh +++ b/images/linux/scripts/installers/basic.sh @@ -12,11 +12,4 @@ for package in $common_packages $cmd_packages; do apt-get install -y --no-install-recommends $package done -# 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 $cmd_packages; do - if ! command -v $cmd; then - echo "$cmd was not installed" - exit 1 - fi -done +invoke_tests "Apt" \ No newline at end of file diff --git a/images/linux/scripts/installers/codeql-bundle.sh b/images/linux/scripts/installers/codeql-bundle.sh index 8d1ed80fa..80062464a 100644 --- a/images/linux/scripts/installers/codeql-bundle.sh +++ b/images/linux/scripts/installers/codeql-bundle.sh @@ -23,6 +23,3 @@ touch "$extraction_directory/pinned-version" # Touch a file to indicate to the toolcache that setting up CodeQL is complete. touch "$extraction_directory.complete" - -# Test that the tool has been extracted successfully. -"$AGENT_TOOLSDIRECTORY/CodeQL/$codeql_bundle_version/x64/codeql/codeql" version diff --git a/images/linux/scripts/installers/dotnetcore-sdk.sh b/images/linux/scripts/installers/dotnetcore-sdk.sh index e8542aace..c1a1b9ee0 100644 --- a/images/linux/scripts/installers/dotnetcore-sdk.sh +++ b/images/linux/scripts/installers/dotnetcore-sdk.sh @@ -94,3 +94,5 @@ setEtcEnvironmentVariable DOTNET_NOLOGO 1 setEtcEnvironmentVariable DOTNET_MULTILEVEL_LOOKUP 0 prependEtcEnvironmentPath /home/runner/.dotnet/tools echo 'export PATH="$PATH:$HOME/.dotnet/tools"' | tee -a /etc/skel/.bashrc + +invoke_tests "DotnetSDK" \ No newline at end of file diff --git a/images/linux/scripts/tests/Apt.Tests.ps1 b/images/linux/scripts/tests/Apt.Tests.ps1 new file mode 100644 index 000000000..cf0309bd3 --- /dev/null +++ b/images/linux/scripts/tests/Apt.Tests.ps1 @@ -0,0 +1,14 @@ +Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" + +$cmd = (Get-ToolsetContent).apt.cmd_packages + +Describe "Apt" { + + $testCases = $cmd | ForEach-Object { + @{ toolName = $_ } + } + + It " is available" -TestCases $testCases { + (Get-Command -Name $toolName).CommandType | Should -BeExactly "Application" + } +} \ No newline at end of file diff --git a/images/linux/scripts/tests/DotnetSDK.Tests.ps1 b/images/linux/scripts/tests/DotnetSDK.Tests.ps1 new file mode 100644 index 000000000..61eb7bf94 --- /dev/null +++ b/images/linux/scripts/tests/DotnetSDK.Tests.ps1 @@ -0,0 +1,31 @@ +Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" + +Describe "Dotnet" { + + BeforeAll { + $dotnetSDKs = dotnet --list-sdks | ConvertTo-Json + $dotnetRuntimes = dotnet --list-runtimes | ConvertTo-Json + } + + $dotnetVersions = (Get-ToolsetContent).dotnet.versions + + Context "Default" { + It "Default Dotnet SDK is available" { + "dotnet --version" | Should -ReturnZeroExitCode + } + } + + foreach ($version in $dotnetVersions) { + Context "Dotnet $version" { + $dotnet = @{ dotnetVersion = $version } + + It "SDK $version is available" -TestCases $dotnet { + $dotnetSDKs | Should -Match "$dotnetVersion.[1-9]*" + } + + It "Runtime $version is available" -TestCases $dotnet { + $dotnetRuntimes | Should -Match "$dotnetVersion.[1-9]*" + } + } + } +} \ No newline at end of file diff --git a/images/linux/scripts/tests/Toolset.Tests.ps1 b/images/linux/scripts/tests/Toolset.Tests.ps1 index c3d51704b..ef331c0b6 100644 --- a/images/linux/scripts/tests/Toolset.Tests.ps1 +++ b/images/linux/scripts/tests/Toolset.Tests.ps1 @@ -22,6 +22,10 @@ Describe "Toolset" { tools = @("bin/ruby") command = "--version" } + CodeQL = @{ + tools = @("codeql/codeql") + command = "version" + } } foreach($tool in $tools) { @@ -43,7 +47,7 @@ Describe "Toolset" { $toolExecs = $toolsExecutables[$toolName] $foundVersion = Get-Item $expectedVersionPath ` - | Sort-Object -Property {[version]$_.name} -Descending ` + | Sort-Object -Property {[SemVer]$_.name} -Descending ` | Select-Object -First 1 $foundVersionPath = Join-Path $foundVersion $tool.arch diff --git a/images/linux/toolsets/toolset-1604.json b/images/linux/toolsets/toolset-1604.json index ee5a88b6a..cafe41f2f 100644 --- a/images/linux/toolsets/toolset-1604.json +++ b/images/linux/toolsets/toolset-1604.json @@ -69,6 +69,14 @@ "2.7.*", "3.0.*" ] + }, + { + "name": "CodeQL", + "platform" : "linux", + "arch": "x64", + "versions": [ + "*" + ] } ], "android": { diff --git a/images/linux/toolsets/toolset-1804.json b/images/linux/toolsets/toolset-1804.json index 3444f50d9..056a57e2b 100644 --- a/images/linux/toolsets/toolset-1804.json +++ b/images/linux/toolsets/toolset-1804.json @@ -69,6 +69,14 @@ "2.7.*", "3.0.*" ] + }, + { + "name": "CodeQL", + "platform" : "linux", + "arch": "x64", + "versions": [ + "*" + ] } ], "android": { diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index e591d2da4..5da314ab6 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -57,6 +57,14 @@ "2.7.*", "3.0.*" ] + }, + { + "name": "CodeQL", + "platform" : "linux", + "arch": "x64", + "versions": [ + "*" + ] } ], "android": {