Skip to content

Commit bd819a6

Browse files
committed
Copy test changes from nightly branch
1 parent 0408104 commit bd819a6

File tree

7 files changed

+229
-4
lines changed

7 files changed

+229
-4
lines changed

tests/Microsoft.DotNet.Docker.Tests/DotNetImageRepo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public enum DotNetImageRepo
1515
Aspnet = 1 << 3,
1616
Monitor = 1 << 4,
1717
Aspire_Dashboard = 1 << 5,
18+
Yarp = 1 << 6,
1819
}

tests/Microsoft.DotNet.Docker.Tests/ProductImageData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private string GetTagName(DotNetImageRepo imageRepo)
189189
case DotNetImageRepo.Runtime_Deps:
190190
case DotNetImageRepo.Monitor:
191191
case DotNetImageRepo.Aspire_Dashboard:
192+
case DotNetImageRepo.Yarp:
192193
imageVersion = Version;
193194
os = OSTag;
194195
break;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
using Xunit;
10+
using Xunit.Abstractions;
11+
12+
namespace Microsoft.DotNet.Docker.Tests;
13+
14+
[Trait("Category", "yarp")]
15+
public class YarpImageTests(ITestOutputHelper outputHelper) : CommonRuntimeImageTests(outputHelper)
16+
{
17+
private const string AppPath = "/app";
18+
19+
private const int YarpWebPort = 5000;
20+
21+
22+
protected override DotNetImageRepo ImageRepo => DotNetImageRepo.Yarp;
23+
24+
public static IEnumerable<object[]> GetImageData() =>
25+
TestData.GetYarpImageData()
26+
.Select(imageData => new object[] { imageData });
27+
28+
[DotNetTheory]
29+
[MemberData(nameof(GetImageData))]
30+
public async Task VerifyBasicScenario(ProductImageData imageData)
31+
{
32+
YarpBasicScenario testScenario = new(YarpWebPort, imageData, DockerHelper, OutputHelper);
33+
await testScenario.ExecuteAsync();
34+
}
35+
36+
[DotNetTheory]
37+
[MemberData(nameof(GetImageData))]
38+
public void VerifyEnvironmentVariables(ProductImageData imageData)
39+
{
40+
IEnumerable<EnvironmentVariableInfo> expectedVariables =
41+
[
42+
// Unset ASPNETCORE_HTTP_PORTS from base image
43+
new EnvironmentVariableInfo("ASPNETCORE_HTTP_PORTS", string.Empty),
44+
new EnvironmentVariableInfo("ASPNETCORE_URLS", "http://+:5000"),
45+
];
46+
47+
string imageTag = imageData.GetImage(ImageRepo, DockerHelper);
48+
EnvironmentVariableInfo.Validate(expectedVariables, imageTag, imageData, DockerHelper);
49+
}
50+
51+
[LinuxImageTheory]
52+
[MemberData(nameof(GetImageData))]
53+
public void VerifyInsecureFiles(ProductImageData imageData) => VerifyCommonInsecureFiles(imageData);
54+
55+
[LinuxImageTheory]
56+
[MemberData(nameof(GetImageData))]
57+
public void VerifyShellNotInstalledForDistroless(ProductImageData imageData)
58+
=> VerifyCommonShellNotInstalledForDistroless(imageData);
59+
60+
[DotNetTheory]
61+
[MemberData(nameof(GetImageData))]
62+
public void VerifyNoSasToken(ProductImageData imageData) => VerifyCommonNoSasToken(imageData);
63+
64+
[DotNetTheory]
65+
[MemberData(nameof(GetImageData))]
66+
public void VerifyDefaultUser(ProductImageData imageData) => VerifyCommonDefaultUser(imageData);
67+
}

tests/Microsoft.DotNet.Docker.Tests/StaticTagTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ public enum VersionType
3131
private const string SingleNumberRegex = @"\d+";
3232
private const string MajorVersionRegex = SingleNumberRegex;
3333
private const string MajorMinorVersionRegex = @$"{SingleNumberRegex}\.{SingleNumberRegex}";
34-
private static readonly string[] ApplianceRepos = { "monitor", "monitor-base", "aspire-dashboard" };
34+
private static readonly string[] ApplianceRepos =
35+
[
36+
"monitor",
37+
"monitor-base",
38+
"aspire-dashboard",
39+
"yarp"
40+
];
3541

3642
private enum TestType
3743
{

tests/Microsoft.DotNet.Docker.Tests/TestData.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ public static class TestData
211211

212212
new ProductImageData { Version = V10_0_Preview, OS = OS.Noble, Arch = Arch.Amd64 },
213213
new ProductImageData { Version = V10_0_Preview, OS = OS.NobleChiseled, Arch = Arch.Amd64, SdkOS = OS.Noble },
214-
new ProductImageData { Version = V10_0_Preview, OS = OS.NobleChiseled, Arch = Arch.Amd64, SdkOS = OS.Noble },
215214
new ProductImageData { Version = V10_0_Preview, OS = OS.NobleChiseled, Arch = Arch.Amd64, SdkOS = OS.Noble,
216215
ImageVariant = DotNetImageVariant.Composite, SupportedImageRepos = DotNetImageRepo.Aspnet },
217216
new ProductImageData { Version = V10_0_Preview, OS = OS.NobleChiseled, Arch = Arch.Amd64, SdkOS = OS.Noble,
@@ -384,13 +383,18 @@ public static class TestData
384383
},
385384
};
386385

386+
private static readonly ProductImageData[] s_YarpTestData =
387+
[
388+
];
389+
387390
public static IEnumerable<ProductImageData> AllImageData =>
388391
[
389392
..s_linuxTestData,
390393
..s_windowsTestData,
391394
..s_AspireDashboardTestData,
392395
..s_linuxMonitorTestData,
393-
..s_windowsMonitorTestData
396+
..s_windowsMonitorTestData,
397+
..s_YarpTestData,
394398
];
395399

396400
public static IEnumerable<ProductImageData> GetImageData(
@@ -440,6 +444,20 @@ public static IEnumerable<ProductImageData> GetMonitorImageData()
440444
.Cast<ProductImageData>();
441445
}
442446

447+
public static IEnumerable<ProductImageData> GetYarpImageData()
448+
{
449+
if (!DockerHelper.IsLinuxContainerModeEnabled)
450+
{
451+
return [];
452+
}
453+
454+
return s_YarpTestData
455+
.FilterImagesByPath(DotNetImageRepo.Yarp)
456+
.FilterImagesByArch()
457+
.FilterImagesByOs()
458+
.Cast<ProductImageData>();
459+
}
460+
443461
public static IEnumerable<ImageData> FilterImagesByArch(this IEnumerable<ImageData> imageData)
444462
{
445463
string archFilterPattern = GetFilterRegexPattern("IMAGE_ARCH");
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#nullable enable
2+
3+
using System.IO;
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Threading.Tasks;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Microsoft.DotNet.Docker.Tests;
11+
12+
public class YarpBasicScenario : ITestScenario
13+
{
14+
private readonly DockerHelper _dockerHelper;
15+
16+
private readonly ITestOutputHelper _outputHelper;
17+
18+
private readonly ProductImageData _imageData;
19+
20+
private readonly string _imageTag;
21+
22+
private readonly int _webPort;
23+
24+
public YarpBasicScenario(
25+
int webPort,
26+
ProductImageData imageData,
27+
DockerHelper dockerHelper,
28+
ITestOutputHelper outputHelper)
29+
{
30+
_dockerHelper = dockerHelper;
31+
_imageData = imageData;
32+
_outputHelper = outputHelper;
33+
_webPort = webPort;
34+
35+
_imageTag = _imageData.GetImage(DotNetImageRepo.Yarp, _dockerHelper);
36+
}
37+
38+
public async Task ExecuteAsync()
39+
{
40+
string containerName = _imageData.GetIdentifier(nameof(YarpBasicScenario));
41+
using TempFileContext configFile = FileHelper.UseTempFile();
42+
string sampleContainer = $"{containerName}_aspnetapp";
43+
44+
try
45+
{
46+
// Deploy the aspnet sample app
47+
_dockerHelper.Run(
48+
image: "mcr.microsoft.com/dotnet/samples:aspnetapp",
49+
name: sampleContainer,
50+
detach: true,
51+
optionalRunArgs: "",
52+
skipAutoCleanup: true);
53+
54+
File.WriteAllText(configFile.Path, ConfigFileContent);
55+
56+
_dockerHelper.Run(
57+
image: _imageTag,
58+
name: containerName,
59+
detach: true,
60+
optionalRunArgs: $"-p {_webPort} -v {configFile.Path}:/etc/yarp.config --link {sampleContainer}:aspnetapp1",
61+
skipAutoCleanup: true);
62+
63+
// base uri should return 404
64+
HttpResponseMessage notFoundResponse = await WebScenario.GetHttpResponseFromContainerAsync(
65+
containerName,
66+
_dockerHelper,
67+
_outputHelper,
68+
_webPort,
69+
pathAndQuery: "/");
70+
71+
Assert.Equal(HttpStatusCode.NotFound, notFoundResponse.StatusCode);
72+
73+
// /aspnetapp should return a valid response
74+
HttpResponseMessage okResponse = await WebScenario.GetHttpResponseFromContainerAsync(
75+
containerName,
76+
_dockerHelper,
77+
_outputHelper,
78+
_webPort,
79+
pathAndQuery: "/aspnetapp");
80+
81+
Assert.Equal(HttpStatusCode.OK, okResponse.StatusCode);
82+
}
83+
finally
84+
{
85+
_dockerHelper.DeleteContainer(containerName);
86+
_dockerHelper.DeleteContainer(sampleContainer);
87+
}
88+
}
89+
90+
private const string ConfigFileContent = """
91+
{
92+
"Logging": {
93+
"LogLevel": {
94+
"Default": "Information",
95+
"Microsoft": "Information",
96+
"Microsoft.Hosting.Lifetime": "Information"
97+
}
98+
},
99+
"AllowedHosts": "*",
100+
"ReverseProxy": {
101+
"Routes": {
102+
"route1": {
103+
"ClusterId": "cluster1",
104+
"Match": {
105+
"Path": "/aspnetapp/{**catch-all}"
106+
},
107+
"Transforms": [
108+
{ "PathRemovePrefix": "/aspnetapp" }
109+
]
110+
}
111+
},
112+
"Clusters": {
113+
"cluster1": {
114+
"Destinations": {
115+
"destination1": {
116+
"Address": "http://aspnetapp1:8080"
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
""";
124+
}

tests/performance/ImageSize.nightly.linux.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,15 @@
405405
"src/sdk/10.0/trixie-slim/arm64v8": 952784503,
406406
"src/sdk/10.0/noble/amd64": 874884561,
407407
"src/sdk/10.0/noble/arm32v7": 758582419,
408-
"src/sdk/10.0/noble/arm64v8": 896400197
408+
"src/sdk/10.0/noble/arm64v8": 896400197,
409+
"src/sdk/10.0/alpine3.21-aot/amd64": 720060909,
410+
"src/sdk/10.0/alpine3.21-aot/arm64v8": 738892101,
411+
"src/sdk/10.0/azurelinux3.0-aot/amd64": 1192447426,
412+
"src/sdk/10.0/azurelinux3.0-aot/arm64v8": 1201391993,
413+
"src/sdk/10.0/trixie-slim-aot/amd64": 896392658,
414+
"src/sdk/10.0/trixie-slim-aot/arm64v8": 952784503,
415+
"src/sdk/10.0/noble-aot/amd64": 874884561,
416+
"src/sdk/10.0/noble-aot/arm64v8": 896400197
409417
},
410418
"dotnet/nightly/monitor": {
411419
"src/monitor/8.0/ubuntu-chiseled/amd64": 127821834,

0 commit comments

Comments
 (0)