forked from dotnet/dotnet-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.ps1
123 lines (100 loc) · 3.45 KB
/
run-tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env pwsh
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
[cmdletbinding()]
param(
[string]$Version,
[string]$Architecture,
[string]$OS,
[string]$Registry,
[string]$RepoPrefix,
[switch]$DisableHttpVerification,
[switch]$PullImages,
[string]$ImageInfoPath,
[ValidateSet("runtime", "runtime-deps", "aspnet", "sdk", "pre-build", "sample", "image-size", "monitor")]
[string[]]$TestCategories = @("runtime", "runtime-deps", "aspnet", "sdk", "monitor")
)
function Log {
param ([string] $Message)
Write-Output $Message
}
function Exec {
param ([string] $Cmd)
Log "Executing: '$Cmd'"
Invoke-Expression $Cmd
if ($LASTEXITCODE -ne 0) {
throw "Failed: '$Cmd'"
}
}
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$EngCommonDir = "$PSScriptRoot/../eng/common"
$DotnetInstallDir = "$PSScriptRoot/../.dotnet"
& $EngCommonDir/Install-DotNetSdk.ps1 -InstallPath $DotnetInstallDir
# Ensure that ImageBuilder image is pulled because some tests require it
& $EngCommonDir/Get-ImageBuilder.ps1
$activeOS = docker version -f "{{ .Server.Os }}"
Push-Location "$PSScriptRoot\Microsoft.DotNet.Docker.Tests"
Try {
# Run Tests
if ([string]::IsNullOrWhiteSpace($Architecture)) {
$Architecture = "amd64"
}
if ($DisableHttpVerification) {
$env:DISABLE_HTTP_VERIFICATION = 1
}
else {
$env:DISABLE_HTTP_VERIFICATION = $null
}
if ($PullImages) {
$env:PULL_IMAGES = 1
}
else {
$env:PULL_IMAGES = $null
}
# By default, account for the OS having a -slim variant, except for mariner which has a -distroless variant that needs to be tested separately.
if (-not $OS.Contains("mariner")) {
$OS += "*"
}
$env:IMAGE_ARCH = $Architecture
$env:IMAGE_OS = $OS
$env:IMAGE_VERSION = $Version
$env:REGISTRY = $Registry
$env:REPO_PREFIX = $RepoPrefix
$env:IMAGE_INFO_PATH = $ImageInfoPath
$env:SOURCE_REPO_ROOT = (Get-Item "$PSScriptRoot").Parent.FullName
$ENV:SOURCE_BRANCH = & $PSScriptRoot/../eng/Get-Branch.ps1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_MULTILEVEL_LOOKUP = '0'
$testFilter = ""
if ($TestCategories) {
# Construct an expression that filters the test to each of the
# selected TestCategories (using an OR operator between each category).
# See https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
$TestCategories | foreach {
# Skip pre-build tests on Windows because of missing pre-reqs (https://github.com/dotnet/dotnet-docker/issues/2261)
if ($_ -eq "pre-build" -and $activeOS -eq "windows") {
Write-Warning "Skipping pre-build tests for Windows containers"
} else {
if ($testFilter) {
$testFilter += "|"
}
$testFilter += "Category=$_"
}
}
if (-not $testFilter) {
exit;
}
$testFilter = "--filter `"$testFilter`""
}
Exec "$DotnetInstallDir/dotnet test $testFilter --logger:trx"
if ($TestCategories.Contains('image-size')) {
& ../performance/Validate-ImageSize.ps1 -PullImages:$PullImages -ValidationMode Integrity
}
}
Finally {
Pop-Location
}