Update e2e test infrastructure

This commit is contained in:
IvanZosimov 2023-04-19 13:40:44 +02:00
parent b72f430d36
commit 180a15970f
7 changed files with 92 additions and 112 deletions

View File

@ -33,7 +33,7 @@ jobs:
3.0.x 3.0.x
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 2.2.402, 3.1.404, 3.0 run: __tests__/verify-dotnet.ps1 -Patterns "^2.2.402$", "^3.1.404$", "^3.0"
test-setup-full-version: test-setup-full-version:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -62,7 +62,7 @@ jobs:
NUGET_AUTH_TOKEN: NOTATOKEN NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 3.1.201, 2.2.402 -CheckNugetConfig run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.201$", "^2.2.402$" -CheckNugetConfig
test-setup-without-patch-version: test-setup-without-patch-version:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -87,7 +87,7 @@ jobs:
dotnet-version: '2.2' dotnet-version: '2.2'
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 3.1, 2.2 run: __tests__/verify-dotnet.ps1 -Patterns "^3.1", "^2.2"
test-setup-prerelease-version: test-setup-prerelease-version:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -107,7 +107,7 @@ jobs:
dotnet-version: '3.1.100-preview1-014459' dotnet-version: '3.1.100-preview1-014459'
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 3.1.100-preview1-014459 run: __tests__/verify-dotnet.ps1 -Patterns "3.1.100-preview1-014459"
test-setup-latest-patch-version: test-setup-latest-patch-version:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -131,7 +131,7 @@ jobs:
dotnet-version: 2.2.X dotnet-version: 2.2.X
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 2.2, 3.1 run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
test-setup-with-wildcard: test-setup-with-wildcard:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -155,7 +155,7 @@ jobs:
dotnet-version: 2.2.* dotnet-version: 2.2.*
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 3.1, 2.2 run: __tests__/verify-dotnet.ps1 -Patterns "^3.1", "^2.2"
test-setup-global-json-specified-and-version: test-setup-global-json-specified-and-version:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -181,7 +181,7 @@ jobs:
global-json-file: ./subdirectory/global.json global-json-file: ./subdirectory/global.json
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 2.2.207, 3.1 run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
test-setup-with-dotnet-quality: test-setup-with-dotnet-quality:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -203,7 +203,7 @@ jobs:
dotnet-quality: 'preview' dotnet-quality: 'preview'
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 7.0 -ContainedPattern "preview" run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"
test-dotnet-version-output-during-single-version-installation: test-dotnet-version-output-during-single-version-installation:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
@ -262,7 +262,7 @@ jobs:
test-proxy: test-proxy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: mcr.microsoft.com/dotnet/core/runtime-deps:3.0-bionic image: ubuntu:latest
options: --dns 127.0.0.1 options: --dns 127.0.0.1
services: services:
squid-proxy: squid-proxy:
@ -275,22 +275,29 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Clear tool cache - name: Install Powershell
run: rm -rf "/usr/share/dotnet"
- name: Install curl
run: | run: |
apt update apt-get update
apt -y install curl apt-get install -y wget apt-transport-https software-properties-common
- name: Setup dotnet 3.1.201 wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
apt-get update
apt-get install -y powershell
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Setup dotnet 6.0
uses: ./ uses: ./
with: with:
dotnet-version: 3.1.201 dotnet-version: 6.0
source-url: https://api.nuget.org/v3/index.json source-url: https://api.nuget.org/v3/index.json
env: env:
NUGET_AUTH_TOKEN: NOTATOKEN NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 3.1.201 -CheckNugetConfig run: |
__tests__/verify-dotnet.ps1 -Patterns "^6.0" -CheckNugetConfig
test-bypass-proxy: test-bypass-proxy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -300,8 +307,9 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Clear tool cache - name: Clear toolcache
run: rm -rf "/usr/share/dotnet" shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Setup dotnet 3.1.201 - name: Setup dotnet 3.1.201
uses: ./ uses: ./
with: with:
@ -311,4 +319,4 @@ jobs:
NUGET_AUTH_TOKEN: NOTATOKEN NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet - name: Verify dotnet
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns 3.1.201 -CheckNugetConfig run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.201$" -CheckNugetConfig

View File

@ -18,7 +18,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest] operating-system: [ubuntu-latest, windows-latest, macOS-latest]
dotnet-version: ['2.1', '2.2', '3.0', '3.1', '5.0'] dotnet-version: ['2.1', '2.2', '3.0', '3.1', '5.0', '6.0', '7.0']
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -29,9 +29,7 @@ jobs:
uses: ./ uses: ./
with: with:
dotnet-version: ${{ matrix.dotnet-version }} dotnet-version: ${{ matrix.dotnet-version }}
- name: Check installed version - name: Verify installed version
shell: pwsh shell: pwsh
run: | run: |
$version = & dotnet --version __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.dotnet-version }}"
Write-Host "Installed version: $version"
if (-not $version.StartsWith("${{ matrix.dotnet-version }}")) { throw "Unexpected version" }

4
.gitignore vendored
View File

@ -3,8 +3,8 @@ global.json
lib/ lib/
node_modules/ node_modules/
__tests__/runner/* __tests__/runner/*
__tests__/sample-csproj/bin/ __tests__/e2e-test-csproj/bin/
__tests__/sample-csproj/obj/ __tests__/e2e-test-csproj/obj/
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore # Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs # Logs

View File

@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace test_csproj namespace test_csproj
{ {
@ -8,7 +9,10 @@ namespace test_csproj
[TestMethod] [TestMethod]
public void TestMethod() public void TestMethod()
{ {
Assert.AreEqual((1 + 1), 2); Console.WriteLine("TestMethod");
int calculatedResult = 1000 / 25;
int expectedResult = 40;
Assert.AreEqual(calculatedResult, expectedResult);
} }
} }
} }

View File

@ -2,11 +2,11 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(TEST_TARGET_FRAMEWORK)</TargetFramework> <TargetFramework>$(TEST_TARGET_FRAMEWORK)</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<!-- These packages will be downloaded over the network for testing proxy settings -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" /> <PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" /> <PackageReference Include="MSTest.TestFramework" Version="1.1.18" />

View File

@ -1,57 +1,68 @@
<#
.DESCRIPTION
Verifies that installed on the machine .NET SDK versions match the input patterns.
Optionally checks that the nuget.config file is generated correctly.
.PARAMETER Patterns
Specifies the regular expression patterns that should be matched with the installed
on the machine .NET SDK versions. The number of patterns should be equal to the number
of installed .NET versions.
.PARAMETER CheckNugetConfig
Switches the check for the existence of the nuget.config file.
.EXAMPLE
PS> .\verify-dotnet.ps1 -Paterns "^3.1.200$", "^6.0" -CheckNugetConfig
#>
param( param(
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true)]
[string[]]$Patterns, [string[]]$Patterns,
[ValidateNotNullOrEmpty()]
[string]$ContainedPattern,
[switch]$CheckNugetConfig [switch]$CheckNugetConfig
) )
if ($CheckNugetConfig.IsPresent) { $PatternsList = [System.Collections.ArrayList]($Patterns)
if (!(Test-Path "../nuget.config"))
{ if ($CheckNugetConfig.IsPresent -and !(Test-Path "../nuget.config")) {
throw "The nuget.config file is not generated correctly." throw "The nuget.config file is not generated correctly."
}
} }
if (!$Patterns.Count) $PatternsCount = $PatternsList.Count
{
throw "At least 1 dotnet-version pattern should be supplied to script."
}
Write-Host "Those patterns were supplied to the script: $($Patterns -join ', ')." Write-Host "Those patterns were supplied to the script: $($PatternsList -join ', ')."
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path } $dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
Write-Host "Found: '$dotnet'" Write-Host "Found: '$dotnet'"
# SDKs are listed on multiple lines with the path afterwards in square brackets # SDKs are listed on multiple lines with the path afterwards in square brackets
$versions = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() } $Versions = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() }
Write-Host "Installed versions: $($versions -join ', ')." Write-Host "Found installed versions: $($Versions -join ', ')."
$InstalledVersionCount = 0 $InstalledVersionCount = $Versions.Count
foreach($pattern in $Patterns)
foreach($version in $Versions)
{ {
foreach ($version in $versions) foreach($pattern in $PatternsList)
{ {
if ($ContainedPattern) if ($version -match $pattern)
{ {
if ($version.StartsWith($pattern.ToString()) -and $version.Contains($ContainedPattern)) $PatternsList.Remove($pattern)
{ $InstalledVersionCount--
$InstalledVersionCount++ break
}
} }
elseif ($version.StartsWith($pattern.ToString()))
{
$InstalledVersionCount++
}
} }
} }
if ( $InstalledVersionCount -ne $Patterns.Count)
if ( $InstalledVersionCount -ne 0)
{ {
throw "An unexpected version of Dotnet is found on the machine, please check the script's dotnet-version patterns." throw "An unexpected version of Dotnet is found on the machine, please check the correctness of the -Patterns input."
} }
Write-Host "Changing directory to the ./__tests__/e2e-test-csproj" Write-Host "Changing directory to the ./__tests__/e2e-test-csproj"
Set-Location ./__tests__/e2e-test-csproj $workingDir = Get-Location
$testProjectDir = "./__tests__/e2e-test-csproj"
Set-Location $testProjectDir
$targetFrameworkVersionMapping = @{ $targetFrameworkVersionMap = @{
"1.0" = "netcoreapp1.0"; "1.0" = "netcoreapp1.0";
"1.1" = "netcoreapp1.1"; "1.1" = "netcoreapp1.1";
"2.0" = "netcoreapp2.0"; "2.0" = "netcoreapp2.0";
@ -64,14 +75,17 @@ $targetFrameworkVersionMapping = @{
"7.0" = "net7.0"; "7.0" = "net7.0";
} }
foreach ($version in $versions) foreach ($version in $Versions)
{ {
# Creating temporary global.json file inside e2e-test-csproj dir and setting exact version of .NET inside allows to override default behavior of .NET and run build and tests on that exact version.
Write-Host "Creating temporary global.json file for $version .NET version." Write-Host "Creating temporary global.json file for $version .NET version."
& $dotnet new globaljson --sdk-version $version --force & $dotnet new globaljson --sdk-version $version --force
Write-Host "The global.json file for the version $version is created. Currently used .NET version is: $(& $dotnet --version)" Write-Host "The global.json file for the version $version is created. Currently used .NET version is: $(& $dotnet --version)."
# Environment variable TEST_TARGET_FRAMEWORK is used inside the test.csproj file to target required framework version
$version -match "^(?<key>\d+\.\d+)" $version -match "^(?<key>\d+\.\d+)"
Write-Host "Setting the TEST_TARGET_FRAMEWORK environment variable to $($targetFrameworkVersionMapping[$Matches.key])" Write-Host "Setting the TEST_TARGET_FRAMEWORK environment variable to $($targetFrameworkVersionMap[$Matches.key])"
[Environment]::SetEnvironmentVariable('TEST_TARGET_FRAMEWORK', $($targetFrameworkVersionMapping[$Matches.key])) [Environment]::SetEnvironmentVariable('TEST_TARGET_FRAMEWORK', $($targetFrameworkVersionMap[$Matches.key]))
Write-Host "Building test C# project with $version .NET version." Write-Host "Building test C# project with $version .NET version."
& $dotnet build --no-cache & $dotnet build --no-cache
@ -89,8 +103,8 @@ foreach ($version in $versions)
Write-Host "Tests are completed successfully!" Write-Host "Tests are completed successfully!"
Write-Host "Removing temprary global.json file." Write-Host "Removing temporary global.json file."
Remove-Item ./global.json Remove-Item ./global.json
} }
Set-Location ../.. Set-Location $workingDir

View File

@ -1,44 +0,0 @@
if [ -z "$1" ]; then
echo "Must supply dotnet version argument"
exit 1
fi
if [ ! -f "../nuget.config" ]; then
echo "nuget file not generated correctly"
exit 1
fi
dotnet_version="$(dotnet --version)"
echo "Found dotnet version '$dotnet_version'"
if [ -z "$(echo $dotnet_version | grep $1)" ]; then
echo "Unexpected version"
exit 1
fi
if [ -n "$2" ]; then
dotnet_version="$(dotnet --list-sdks)"
echo "Found dotnet version '$dotnet_version'"
if [ -z "$(echo $dotnet_version | grep $2)" ]; then
echo "Unexpected version"
exit 1
fi
fi
echo "Building sample csproj"
dotnet build __tests__/sample-csproj/ --no-cache || exit 1
echo "Testing compiled app"
sample_output=$(dotnet test __tests__/sample-csproj/ --no-build)
echo "Sample output: $sample_output"
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
if [ -n "$2" ]; then
if [ -z "$(echo $sample_output | grep "Test Run Successful.*Test Run Successful.")" ]; then
echo "Unexpected output"
exit 1
fi
else
if [ -z "$(echo $sample_output | grep "Test Run Successful.")" ]; then
echo "Unexpected output"
exit 1
fi
fi