diff --git a/images/linux/scripts/installers/Configure-Toolset.ps1 b/images/linux/scripts/installers/Configure-Toolset.ps1 index 4a145a5d5..1b30dad30 100644 --- a/images/linux/scripts/installers/Configure-Toolset.ps1 +++ b/images/linux/scripts/installers/Configure-Toolset.ps1 @@ -4,6 +4,8 @@ ## Desc: Configure toolset ################################################################################ +Import-Module "$env:HELPER_SCRIPTS/Tests.Helpers.psm1" -DisableNameChecking + function Get-ToolsetToolFullPath { param @@ -93,3 +95,5 @@ foreach ($tool in $toolset.toolcache) Invoke-Expression -Command $command } } + +Invoke-PesterTests -TestFile "Toolset" -TestName "Toolset" \ No newline at end of file diff --git a/images/linux/scripts/installers/Validate-Toolset.ps1 b/images/linux/scripts/installers/Validate-Toolset.ps1 deleted file mode 100644 index de53f1ddd..000000000 --- a/images/linux/scripts/installers/Validate-Toolset.ps1 +++ /dev/null @@ -1,92 +0,0 @@ -################################################################################ -## File: Validate-Toolset.ps1 -## Team: CI-Build -## Desc: Validate Toolset -################################################################################ - -function Run-ExecutableTests { - param ( - [Parameter(Mandatory)] [string[]] $Executables, - [Parameter(Mandatory)] [string] $ToolPath - ) - $versionCommand = $Executables["command"] - - foreach ($executable in $Executables["tools"]) { - $executablePath = Join-Path $ToolPath $executable - Write-Host "Check $executable..." - if (Test-Path $executablePath) { - Write-Host "$executable is successfully installed: $(& $executablePath $versionCommand)" - } else { - Write-Host "$executablePath is not installed!" - exit 1 - } - } -} - -$ErrorActionPreference = "Stop" - -# Define executables for cached tools -$toolsExecutables = @{ - Python = @{ - tools = @("python", "bin/pip") - command = "--version" - } - node = @{ - tools = @("bin/node", "bin/npm") - command = "--version" - } - PyPy = @{ - tools = @("bin/python", "bin/pip") - command = "--version" - } - go = @{ - tools = @("bin/go") - command = "version" - } - Ruby = @{ - tools = @("bin/ruby") - command = "--version" - } -} - -# Get toolset content -$toolset = Get-Content -Path "$env:INSTALLER_SCRIPT_FOLDER/toolset.json" -Raw -$tools = ConvertFrom-Json -InputObject $toolset | Select-Object -ExpandProperty toolcache - -foreach($tool in $tools) { - - $toolPath = Join-Path $env:AGENT_TOOLSDIRECTORY $tool.name - # Get executables for current tool - $toolExecs = $toolsExecutables[$tool.name] - - foreach ($version in $tool.versions) { - # Add wildcard if missing - if ($version.Split(".").Length -lt 3) { - $version += ".*" - } - - # Check if version folder exists - $expectedVersionPath = Join-Path $toolPath $version - if (-not (Test-Path $expectedVersionPath)) { - Write-Host "Expected $($tool.name) $version folder is not found!" - exit 1 - } - - # Take latest installed version in case if toolset version contains wildcards - $foundVersion = Get-Item $expectedVersionPath ` - | Sort-Object -Property {[version]$_.name} -Descending ` - | Select-Object -First 1 - $foundVersionPath = Join-Path $foundVersion $tool.arch - - if ($toolExecs) { - Write-Host "Run validation test for $($tool.name)($($tool.arch)) $($foundVersion.name) executables..." - Run-ExecutableTests -Executables $toolExecs -ToolPath $foundVersionPath - } - $foundVersionName = $foundVersion.name - if ($tool.name -eq 'PyPy') - { - $pypyVersion = & "$foundVersionPath/bin/python" -c "import sys;print(sys.version.split('\n')[1])" - $foundVersionName = "{0} {1}" -f $foundVersionName, $pypyVersion - } - } -} \ No newline at end of file diff --git a/images/linux/scripts/tests/Toolset.Tests.ps1 b/images/linux/scripts/tests/Toolset.Tests.ps1 new file mode 100644 index 000000000..c3d51704b --- /dev/null +++ b/images/linux/scripts/tests/Toolset.Tests.ps1 @@ -0,0 +1,62 @@ +Describe "Toolset" { + $tools = (Get-ToolsetContent).toolcache + + $toolsExecutables = @{ + Python = @{ + tools = @("python", "bin/pip") + command = "--version" + } + node = @{ + tools = @("bin/node", "bin/npm") + command = "--version" + } + PyPy = @{ + tools = @("bin/python", "bin/pip") + command = "--version" + } + go = @{ + tools = @("bin/go") + command = "version" + } + Ruby = @{ + tools = @("bin/ruby") + command = "--version" + } + } + + foreach($tool in $tools) { + $toolName = $tool.Name + Context "$toolName" { + $toolExecs = $toolsExecutables[$toolName] + + foreach ($version in $tool.versions) { + # Add wildcard if missing + if ($version.Split(".").Length -lt 3) { + $version += ".*" + } + + $expectedVersionPath = Join-Path $env:AGENT_TOOLSDIRECTORY $toolName $version + + It "$version version folder exists" -TestCases @{ ExpectedVersionPath = $expectedVersionPath} { + $ExpectedVersionPath | Should -Exist + } + + $toolExecs = $toolsExecutables[$toolName] + $foundVersion = Get-Item $expectedVersionPath ` + | Sort-Object -Property {[version]$_.name} -Descending ` + | Select-Object -First 1 + $foundVersionPath = Join-Path $foundVersion $tool.arch + + if($toolExecs) { + foreach ($executable in $toolExecs["tools"]) { + $executablePath = Join-Path $foundVersionPath $executable + + It "Validate $executable" -TestCases @{ExecutablePath = $executablePath} { + $ExecutablePath | Should -Exist + } + } + } + } + } + } +} \ No newline at end of file diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index e30f30105..08e56cfca 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -246,8 +246,7 @@ "type": "shell", "scripts": [ "{{template_dir}}/scripts/installers/Install-Toolset.ps1", - "{{template_dir}}/scripts/installers/Configure-Toolset.ps1", - "{{template_dir}}/scripts/installers/Validate-Toolset.ps1" + "{{template_dir}}/scripts/installers/Configure-Toolset.ps1" ], "environment_vars": [ "HELPER_SCRIPTS={{user `helper_script_folder`}}", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index f1ffce716..b2fe43607 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -250,8 +250,7 @@ "type": "shell", "scripts": [ "{{template_dir}}/scripts/installers/Install-Toolset.ps1", - "{{template_dir}}/scripts/installers/Configure-Toolset.ps1", - "{{template_dir}}/scripts/installers/Validate-Toolset.ps1" + "{{template_dir}}/scripts/installers/Configure-Toolset.ps1" ], "environment_vars": [ "HELPER_SCRIPTS={{user `helper_script_folder`}}", diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index a273d884f..f9b00f8e7 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -250,8 +250,7 @@ "type": "shell", "scripts": [ "{{template_dir}}/scripts/installers/Install-Toolset.ps1", - "{{template_dir}}/scripts/installers/Configure-Toolset.ps1", - "{{template_dir}}/scripts/installers/Validate-Toolset.ps1" + "{{template_dir}}/scripts/installers/Configure-Toolset.ps1" ], "environment_vars": [ "HELPER_SCRIPTS={{user `helper_script_folder`}}",