Skip to content

Commit 7eefa05

Browse files
Alirexaaeerhardt
andauthored
Extract Aspire.Hosting.Garnet.Tests project (#4871)
* extract Aspire.Hosting.Garnet.Tests project * Remove Garnet from Hosting and EndToEnd tests. --------- Co-authored-by: Eric Erhardt <[email protected]>
1 parent d7168a4 commit 7eefa05

File tree

14 files changed

+101
-84
lines changed

14 files changed

+101
-84
lines changed

Aspire.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosting", "Hosting", "{830A
520520
EndProject
521521
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Redis.Tests", "tests\Aspire.Hosting.Redis.Tests\Aspire.Hosting.Redis.Tests.csproj", "{1BC02557-B78B-48CE-9D3C-488A6B7672F4}"
522522
EndProject
523+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Garnet.Tests", "tests\Aspire.Hosting.Garnet.Tests\Aspire.Hosting.Garnet.Tests.csproj", "{CAA4A93F-6BEB-42EB-8680-C1CF72928023}"
523524
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.PostgreSQL.Tests", "tests\Aspire.Hosting.PostgreSQL.Tests\Aspire.Hosting.PostgreSQL.Tests.csproj", "{7425E5B2-BC47-4521-AC40-B8CECA329E08}"
524525
EndProject
525526
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Qdrant.Tests", "tests\Aspire.Hosting.Qdrant.Tests\Aspire.Hosting.Qdrant.Tests.csproj", "{8E2AA85E-C351-47B4-AF91-58557FAD5840}"
@@ -1393,6 +1394,10 @@ Global
13931394
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
13941395
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
13951396
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Release|Any CPU.Build.0 = Release|Any CPU
1397+
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1398+
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Debug|Any CPU.Build.0 = Debug|Any CPU
1399+
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Release|Any CPU.ActiveCfg = Release|Any CPU
1400+
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Release|Any CPU.Build.0 = Release|Any CPU
13961401
{8E2AA85E-C351-47B4-AF91-58557FAD5840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13971402
{8E2AA85E-C351-47B4-AF91-58557FAD5840}.Debug|Any CPU.Build.0 = Debug|Any CPU
13981403
{8E2AA85E-C351-47B4-AF91-58557FAD5840}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -1692,6 +1697,7 @@ Global
16921697
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4} = {77CFE74A-32EE-400C-8930-5025E8555256}
16931698
{5CB63205-24F4-4388-A41B-BAF3BEA59866} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
16941699
{588CD2D7-EE70-43C1-8233-330854BDF53C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
1700+
{588CD2D7-EE70-43C1-8233-330854BDF53C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
16951701
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
16961702
{9357EC71-823B-433A-9993-B7CB2FA082D1} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
16971703
{3F7B206E-5457-458F-AA81-9449FA3C1B5C} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
@@ -1708,6 +1714,7 @@ Global
17081714
{C424395C-1235-41A4-BF55-07880A04368C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
17091715
{830A89EC-4029-4753-B25A-068BAE37DEC7} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
17101716
{1BC02557-B78B-48CE-9D3C-488A6B7672F4} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
1717+
{CAA4A93F-6BEB-42EB-8680-C1CF72928023} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
17111718
{8E2AA85E-C351-47B4-AF91-58557FAD5840} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
17121719
{986886B7-0E38-4890-92C3-5B46DE322DAF} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
17131720
{7425E5B2-BC47-4521-AC40-B8CECA329E08} = {830A89EC-4029-4753-B25A-068BAE37DEC7}

tests/Aspire.EndToEnd.Tests/IntegrationServicesFixture.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public Task DumpComponentLogsAsync(TestResourceNames resource, ITestOutputHelper
104104
{
105105
TestResourceNames.cosmos or TestResourceNames.efcosmos => "cosmos",
106106
TestResourceNames.eventhubs => "eventhubs",
107-
TestResourceNames.garnet => "garnet",
108107
TestResourceNames.mongodb => "mongodb",
109108
TestResourceNames.oracledatabase => "oracledatabase",
110109
TestResourceNames.postgres or TestResourceNames.efnpgsql => "postgres",
@@ -146,7 +145,6 @@ private static TestResourceNames GetResourcesToSkip()
146145
"basicservices" => TestResourceNames.mongodb
147146
| TestResourceNames.rabbitmq
148147
| TestResourceNames.redis
149-
| TestResourceNames.garnet
150148
| TestResourceNames.postgres
151149
| TestResourceNames.efnpgsql
152150
| TestResourceNames.sqlserver

tests/Aspire.EndToEnd.Tests/IntegrationServicesTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public IntegrationServicesTests(ITestOutputHelper testOutput, IntegrationService
2828
[InlineData(TestResourceNames.efnpgsql)]
2929
[InlineData(TestResourceNames.rabbitmq)]
3030
[InlineData(TestResourceNames.redis)]
31-
[InlineData(TestResourceNames.garnet)]
3231
[InlineData(TestResourceNames.sqlserver)]
3332
[InlineData(TestResourceNames.efsqlserver)]
3433
public Task VerifyComponentWorks(TestResourceNames resourceName)

tests/Aspire.Hosting.Tests/Garnet/AddGarnetTests.cs renamed to tests/Aspire.Hosting.Garnet.Tests/AddGarnetTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Net.Sockets;
5-
using Aspire.Hosting.Garnet;
5+
using Aspire.Hosting.ApplicationModel;
66
using Aspire.Hosting.Utils;
77
using Microsoft.Extensions.DependencyInjection;
88
using Xunit;
99

10-
namespace Aspire.Hosting.Tests.Garnet;
10+
namespace Aspire.Hosting.Garnet.Tests;
1111

1212
public class AddGarnetTests
1313
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(NetCurrent)</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" />
9+
<ProjectReference Include="..\..\src\Aspire.Hosting.Garnet\Aspire.Hosting.Garnet.csproj" />
10+
<ProjectReference Include="..\..\src\Components\Aspire.StackExchange.Redis\Aspire.StackExchange.Redis.csproj" />
11+
<ProjectReference Include="..\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj" />
12+
13+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Garnet\GarnetContainerImageTags.cs" />
18+
<Compile Include="$(SharedDir)VolumeNameGenerator.cs" Link="Utils\VolumeNameGenerator.cs" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
4+
using Aspire.Components.Common.Tests;
5+
using Aspire.Hosting.Utils;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
9+
using Microsoft.Extensions.Logging;
10+
using Polly;
11+
using StackExchange.Redis;
12+
using Xunit;
13+
using Xunit.Abstractions;
14+
15+
namespace Aspire.Hosting.Garnet.Tests;
16+
17+
public class GarnetFunctionalTests(ITestOutputHelper testOutputHelper)
18+
{
19+
[Fact]
20+
[RequiresDocker]
21+
public async Task VerifyGarnetResource()
22+
{
23+
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
24+
var pipeline = new ResiliencePipelineBuilder()
25+
.AddRetry(new() { MaxRetryAttempts = 10, Delay = TimeSpan.FromSeconds(3) })
26+
.Build();
27+
28+
var builder = CreateDistributedApplicationBuilder();
29+
30+
var garnet = builder.AddGarnet("garnet");
31+
32+
using var app = builder.Build();
33+
34+
await app.StartAsync();
35+
36+
var hb = Host.CreateApplicationBuilder();
37+
38+
hb.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
39+
{
40+
[$"ConnectionStrings:{garnet.Resource.Name}"] = await garnet.Resource.ConnectionStringExpression.GetValueAsync(default)
41+
});
42+
43+
hb.AddRedisClient(garnet.Resource.Name);
44+
45+
using var host = hb.Build();
46+
47+
await host.StartAsync();
48+
49+
var redisClient = host.Services.GetRequiredService<IConnectionMultiplexer>();
50+
51+
await pipeline.ExecuteAsync(async token =>
52+
{
53+
var db = redisClient.GetDatabase();
54+
55+
await db.StringSetAsync("key", "value");
56+
57+
var value = await db.StringGetAsync("key");
58+
59+
Assert.Equal("value", value);
60+
61+
}, cts.Token);
62+
}
63+
64+
private TestDistributedApplicationBuilder CreateDistributedApplicationBuilder()
65+
{
66+
var builder = TestDistributedApplicationBuilder.Create();
67+
builder.Services.AddXunitLogging(testOutputHelper);
68+
return builder;
69+
}
70+
}

tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
1313
<ProjectReference Include="..\..\src\Aspire.Hosting.AWS\Aspire.Hosting.AWS.csproj" IsAspireProjectResource="false" />
1414
<ProjectReference Include="..\..\src\Aspire.Hosting.Dapr\Aspire.Hosting.Dapr.csproj" IsAspireProjectResource="false" />
15-
<ProjectReference Include="..\..\src\Aspire.Hosting.Garnet\Aspire.Hosting.Garnet.csproj" IsAspireProjectResource="false" />
1615
<ProjectReference Include="..\..\src\Aspire.Hosting.MongoDB\Aspire.Hosting.MongoDB.csproj" IsAspireProjectResource="false" />
1716
<ProjectReference Include="..\..\src\Aspire.Hosting.Nats\Aspire.Hosting.Nats.csproj" IsAspireProjectResource="false" />
1817
<ProjectReference Include="..\..\src\Aspire.Hosting.Testing\Aspire.Hosting.Testing.csproj" IsAspireProjectResource="false" />
@@ -26,7 +25,6 @@
2625
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />
2726

2827
<Compile Include="$(TestsSharedDir)Logging\*.cs" LinkBase="shared/Logging" />
29-
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Garnet\GarnetContainerImageTags.cs" />
3028
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Nats\NatsContainerImageTags.cs" />
3129
<Compile Include="$(RepoRoot)src\Aspire.Hosting.MongoDB\MongoDBContainerImageTags.cs" />
3230
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Oracle\OracleContainerImageTags.cs" />

tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Text.Json;
55
using Aspire.Components.Common.Tests;
6-
using Aspire.Hosting.Garnet;
76
using Aspire.Hosting.MongoDB;
87
using Aspire.Hosting.Postgres;
98
using Aspire.Hosting.Publishing;
@@ -480,7 +479,6 @@ public void VerifyTestProgramFullManifest()
480479
"SKIP_RESOURCES": "None",
481480
"ConnectionStrings__tempdb": "{tempdb.connectionString}",
482481
"ConnectionStrings__redis": "{redis.connectionString}",
483-
"ConnectionStrings__garnet": "{garnet.connectionString}",
484482
"ConnectionStrings__postgresdb": "{postgresdb.connectionString}",
485483
"ConnectionStrings__rabbitmq": "{rabbitmq.connectionString}",
486484
"ConnectionStrings__mymongodb": "{mymongodb.connectionString}",
@@ -535,19 +533,6 @@ public void VerifyTestProgramFullManifest()
535533
}
536534
}
537535
},
538-
"garnet": {
539-
"type": "container.v0",
540-
"connectionString": "{garnet.bindings.tcp.host}:{garnet.bindings.tcp.port}",
541-
"image": "{{GarnetContainerImageTags.Registry}}/{{GarnetContainerImageTags.Image}}:{{GarnetContainerImageTags.Tag}}",
542-
"bindings": {
543-
"tcp": {
544-
"scheme": "tcp",
545-
"protocol": "tcp",
546-
"transport": "tcp",
547-
"targetPort": 6379
548-
}
549-
}
550-
},
551536
"postgres": {
552537
"type": "container.v0",
553538
"connectionString": "Host={postgres.bindings.tcp.host};Port={postgres.bindings.tcp.port};Username=postgres;Password={postgres-password.value}",

tests/testproject/Common/TestResourceNames.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ public enum TestResourceNames
1616
redis = 1 << 9,
1717
sqlserver = 1 << 10,
1818
efnpgsql = 1 << 11,
19-
garnet = 1 << 12,
2019
eventhubs = 1 << 13,
2120
efsqlserver = 1 << 16,
2221
efcosmos = 1 << 17,
23-
All = cosmos | dashboard | mongodb | oracledatabase | postgres | rabbitmq | redis | sqlserver | efnpgsql | garnet | eventhubs | efsqlserver | efcosmos
22+
All = cosmos | dashboard | mongodb | oracledatabase | postgres | rabbitmq | redis | sqlserver | efnpgsql | eventhubs | efsqlserver | efcosmos
2423
}
2524

2625
public static class TestResourceNamesExtensions

tests/testproject/TestProject.AppHost/TestProgram.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ private TestProgram(
9595
.WithImageRegistry(AspireTestContainerRegistry);
9696
IntegrationServiceABuilder = IntegrationServiceABuilder.WithReference(redis);
9797
}
98-
if (!resourcesToSkip.HasFlag(TestResourceNames.garnet))
99-
{
100-
var garnet = AppBuilder.AddGarnet("garnet");
101-
IntegrationServiceABuilder = IntegrationServiceABuilder.WithReference(garnet);
102-
}
10398
if (!resourcesToSkip.HasFlag(TestResourceNames.postgres) || !resourcesToSkip.HasFlag(TestResourceNames.efnpgsql))
10499
{
105100
var postgresDbName = "postgresdb";

0 commit comments

Comments
 (0)