diff --git a/images/linux/scripts/helpers/Common.Helpers.psm1 b/images/linux/scripts/helpers/Common.Helpers.psm1 index 3f8ada885..57d9e85a9 100644 --- a/images/linux/scripts/helpers/Common.Helpers.psm1 +++ b/images/linux/scripts/helpers/Common.Helpers.psm1 @@ -32,4 +32,26 @@ function Test-IsUbuntu20 { function Get-ToolsetContent { $toolset = Join-Path $env:INSTALLER_SCRIPT_FOLDER "toolset.json" Get-Content $toolset -Raw | ConvertFrom-Json +} + +function Get-ToolsetValue { + param ( + [Parameter(Mandatory = $true)] + [string] $KeyPath + ) + + $jsonNode = Get-ToolsetContent + + $pathParts = $KeyPath.Split(".") + # try to walk through all arguments consequentially to resolve specific json node + $pathParts | ForEach-Object { + $jsonNode = $jsonNode.$_ + } + return $jsonNode +} + +function Get-AndroidPackages { + $androidSDKManagerPath = "/usr/local/lib/android/sdk/tools/bin/sdkmanager" + $androidPackages = & $androidSDKManagerPath --list --verbose + return $androidPackages } \ No newline at end of file diff --git a/images/linux/scripts/installers/android.sh b/images/linux/scripts/installers/android.sh index 2cfbdd8dd..45e9f6200 100644 --- a/images/linux/scripts/installers/android.sh +++ b/images/linux/scripts/installers/android.sh @@ -7,6 +7,7 @@ # Source the helpers for use with the script source $HELPER_SCRIPTS/os.sh source $HELPER_SCRIPTS/install.sh +source $HELPER_SCRIPTS/invoke-tests.sh function filter_components_by_version { minimumVersion=$1 @@ -77,3 +78,5 @@ echo "y" | ${ANDROID_SDK_ROOT}/tools/bin/sdkmanager ${components[@]} # Add required permissions chmod -R a+rwx ${ANDROID_SDK_ROOT} + +invoke_tests "Android" diff --git a/images/linux/scripts/tests/Android.Tests.ps1 b/images/linux/scripts/tests/Android.Tests.ps1 new file mode 100644 index 000000000..c1c89f0a1 --- /dev/null +++ b/images/linux/scripts/tests/Android.Tests.ps1 @@ -0,0 +1,50 @@ +Describe "Android" { + $androidSdkManagerPackages = Get-AndroidPackages + [int]$platformMinVersion = Get-ToolsetValue "android.platform_min_version" + [version]$buildToolsMinVersion = Get-ToolsetValue "android.build_tools_min_version" + + $platforms = (($androidSdkManagerPackages | Where-Object { "$_".StartsWith("platforms;") }) -replace 'platforms;', '' | + Where-Object { [int]$_.Split("-")[1] -ge $platformMinVersion } | Sort-Object { [int]$_.Split("-")[1] } -Unique | + ForEach-Object { "platforms/${_}" }) + + $buildTools = (($androidSdkManagerPackages | Where-Object { "$_".StartsWith("build-tools;") }) -replace 'build-tools;', '' | + Where-Object { [version]$_ -ge $buildToolsMinVersion } | Sort-Object { [version]$_ } -Unique | + ForEach-Object { "build-tools/${_}" }) + + $androidPackages = @( + $platforms, + $buildTools, + (Get-ToolsetValue "android.extra_list" | ForEach-Object { "extras/${_}" }), + (Get-ToolsetValue "android.addon_list" | ForEach-Object { "add-ons/${_}" }), + (Get-ToolsetValue "android.additional_tools" | ForEach-Object { "${_}" }) + ) | ForEach-Object { $_ } + + BeforeAll { + $ANDROID_SDK_DIR = "/usr/local/lib/android/sdk" + + function Validate-AndroidPackage { + param ( + [Parameter(Mandatory=$true)] + [string]$PackageName + ) + + # Convert 'm2repository;com;android;support;constraint;constraint-layout-solver;1.0.0-beta1' -> + # 'm2repository/com/android/support/constraint/constraint-layout-solver/1.0.0-beta1' + # 'cmake;3.6.4111459' -> 'cmake/3.6.4111459' + # 'patcher;v4' -> 'patcher/v4' + $PackageName = $PackageName.Replace(";", "/") + $targetPath = Join-Path $ANDROID_SDK_DIR $PackageName + $targetPath | Should -Exist + } + } + + + Context "Packages" { + $testCases = $androidPackages | ForEach-Object { @{ PackageName = $_ } } + + It "" -TestCases $testCases { + param ([string] $PackageName) + Validate-AndroidPackage $PackageName + } + } +} \ No newline at end of file