Skip to content

Commit

Permalink
Extract Aspire.Hosting.Garnet.Tests project (#4871)
Browse files Browse the repository at this point in the history
* extract Aspire.Hosting.Garnet.Tests project

* Remove Garnet from Hosting and EndToEnd tests.

---------

Co-authored-by: Eric Erhardt <[email protected]>
  • Loading branch information
Alirexaa and eerhardt authored Jul 29, 2024
1 parent d7168a4 commit 7eefa05
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 84 deletions.
7 changes: 7 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosting", "Hosting", "{830A
EndProject
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}"
EndProject
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}"
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}"
EndProject
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}"
Expand Down Expand Up @@ -1393,6 +1394,10 @@ Global
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Release|Any CPU.Build.0 = Release|Any CPU
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAA4A93F-6BEB-42EB-8680-C1CF72928023}.Release|Any CPU.Build.0 = Release|Any CPU
{8E2AA85E-C351-47B4-AF91-58557FAD5840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E2AA85E-C351-47B4-AF91-58557FAD5840}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E2AA85E-C351-47B4-AF91-58557FAD5840}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1692,6 +1697,7 @@ Global
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4} = {77CFE74A-32EE-400C-8930-5025E8555256}
{5CB63205-24F4-4388-A41B-BAF3BEA59866} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
{588CD2D7-EE70-43C1-8233-330854BDF53C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{588CD2D7-EE70-43C1-8233-330854BDF53C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{9357EC71-823B-433A-9993-B7CB2FA082D1} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
{3F7B206E-5457-458F-AA81-9449FA3C1B5C} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
Expand All @@ -1708,6 +1714,7 @@ Global
{C424395C-1235-41A4-BF55-07880A04368C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{830A89EC-4029-4753-B25A-068BAE37DEC7} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{1BC02557-B78B-48CE-9D3C-488A6B7672F4} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{CAA4A93F-6BEB-42EB-8680-C1CF72928023} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{8E2AA85E-C351-47B4-AF91-58557FAD5840} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{986886B7-0E38-4890-92C3-5B46DE322DAF} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{7425E5B2-BC47-4521-AC40-B8CECA329E08} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.EndToEnd.Tests/IntegrationServicesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public Task DumpComponentLogsAsync(TestResourceNames resource, ITestOutputHelper
{
TestResourceNames.cosmos or TestResourceNames.efcosmos => "cosmos",
TestResourceNames.eventhubs => "eventhubs",
TestResourceNames.garnet => "garnet",
TestResourceNames.mongodb => "mongodb",
TestResourceNames.oracledatabase => "oracledatabase",
TestResourceNames.postgres or TestResourceNames.efnpgsql => "postgres",
Expand Down Expand Up @@ -146,7 +145,6 @@ private static TestResourceNames GetResourcesToSkip()
"basicservices" => TestResourceNames.mongodb
| TestResourceNames.rabbitmq
| TestResourceNames.redis
| TestResourceNames.garnet
| TestResourceNames.postgres
| TestResourceNames.efnpgsql
| TestResourceNames.sqlserver
Expand Down
1 change: 0 additions & 1 deletion tests/Aspire.EndToEnd.Tests/IntegrationServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public IntegrationServicesTests(ITestOutputHelper testOutput, IntegrationService
[InlineData(TestResourceNames.efnpgsql)]
[InlineData(TestResourceNames.rabbitmq)]
[InlineData(TestResourceNames.redis)]
[InlineData(TestResourceNames.garnet)]
[InlineData(TestResourceNames.sqlserver)]
[InlineData(TestResourceNames.efsqlserver)]
public Task VerifyComponentWorks(TestResourceNames resourceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net.Sockets;
using Aspire.Hosting.Garnet;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Aspire.Hosting.Tests.Garnet;
namespace Aspire.Hosting.Garnet.Tests;

public class AddGarnetTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Garnet\Aspire.Hosting.Garnet.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.StackExchange.Redis\Aspire.StackExchange.Redis.csproj" />
<ProjectReference Include="..\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Garnet\GarnetContainerImageTags.cs" />
<Compile Include="$(SharedDir)VolumeNameGenerator.cs" Link="Utils\VolumeNameGenerator.cs" />
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions tests/Aspire.Hosting.Garnet.Tests/GarnetFunctionalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Components.Common.Tests;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Polly;
using StackExchange.Redis;
using Xunit;
using Xunit.Abstractions;

namespace Aspire.Hosting.Garnet.Tests;

public class GarnetFunctionalTests(ITestOutputHelper testOutputHelper)
{
[Fact]
[RequiresDocker]
public async Task VerifyGarnetResource()
{
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var pipeline = new ResiliencePipelineBuilder()
.AddRetry(new() { MaxRetryAttempts = 10, Delay = TimeSpan.FromSeconds(3) })
.Build();

var builder = CreateDistributedApplicationBuilder();

var garnet = builder.AddGarnet("garnet");

using var app = builder.Build();

await app.StartAsync();

var hb = Host.CreateApplicationBuilder();

hb.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
[$"ConnectionStrings:{garnet.Resource.Name}"] = await garnet.Resource.ConnectionStringExpression.GetValueAsync(default)
});

hb.AddRedisClient(garnet.Resource.Name);

using var host = hb.Build();

await host.StartAsync();

var redisClient = host.Services.GetRequiredService<IConnectionMultiplexer>();

await pipeline.ExecuteAsync(async token =>
{
var db = redisClient.GetDatabase();

await db.StringSetAsync("key", "value");

var value = await db.StringGetAsync("key");

Assert.Equal("value", value);

}, cts.Token);
}

private TestDistributedApplicationBuilder CreateDistributedApplicationBuilder()
{
var builder = TestDistributedApplicationBuilder.Create();
builder.Services.AddXunitLogging(testOutputHelper);
return builder;
}
}
2 changes: 0 additions & 2 deletions tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.AWS\Aspire.Hosting.AWS.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Dapr\Aspire.Hosting.Dapr.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Garnet\Aspire.Hosting.Garnet.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.MongoDB\Aspire.Hosting.MongoDB.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Nats\Aspire.Hosting.Nats.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Testing\Aspire.Hosting.Testing.csproj" IsAspireProjectResource="false" />
Expand All @@ -26,7 +25,6 @@
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />

<Compile Include="$(TestsSharedDir)Logging\*.cs" LinkBase="shared/Logging" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Garnet\GarnetContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Nats\NatsContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.MongoDB\MongoDBContainerImageTags.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Oracle\OracleContainerImageTags.cs" />
Expand Down
15 changes: 0 additions & 15 deletions tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Text.Json;
using Aspire.Components.Common.Tests;
using Aspire.Hosting.Garnet;
using Aspire.Hosting.MongoDB;
using Aspire.Hosting.Postgres;
using Aspire.Hosting.Publishing;
Expand Down Expand Up @@ -480,7 +479,6 @@ public void VerifyTestProgramFullManifest()
"SKIP_RESOURCES": "None",
"ConnectionStrings__tempdb": "{tempdb.connectionString}",
"ConnectionStrings__redis": "{redis.connectionString}",
"ConnectionStrings__garnet": "{garnet.connectionString}",
"ConnectionStrings__postgresdb": "{postgresdb.connectionString}",
"ConnectionStrings__rabbitmq": "{rabbitmq.connectionString}",
"ConnectionStrings__mymongodb": "{mymongodb.connectionString}",
Expand Down Expand Up @@ -535,19 +533,6 @@ public void VerifyTestProgramFullManifest()
}
}
},
"garnet": {
"type": "container.v0",
"connectionString": "{garnet.bindings.tcp.host}:{garnet.bindings.tcp.port}",
"image": "{{GarnetContainerImageTags.Registry}}/{{GarnetContainerImageTags.Image}}:{{GarnetContainerImageTags.Tag}}",
"bindings": {
"tcp": {
"scheme": "tcp",
"protocol": "tcp",
"transport": "tcp",
"targetPort": 6379
}
}
},
"postgres": {
"type": "container.v0",
"connectionString": "Host={postgres.bindings.tcp.host};Port={postgres.bindings.tcp.port};Username=postgres;Password={postgres-password.value}",
Expand Down
3 changes: 1 addition & 2 deletions tests/testproject/Common/TestResourceNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public enum TestResourceNames
redis = 1 << 9,
sqlserver = 1 << 10,
efnpgsql = 1 << 11,
garnet = 1 << 12,
eventhubs = 1 << 13,
efsqlserver = 1 << 16,
efcosmos = 1 << 17,
All = cosmos | dashboard | mongodb | oracledatabase | postgres | rabbitmq | redis | sqlserver | efnpgsql | garnet | eventhubs | efsqlserver | efcosmos
All = cosmos | dashboard | mongodb | oracledatabase | postgres | rabbitmq | redis | sqlserver | efnpgsql | eventhubs | efsqlserver | efcosmos
}

public static class TestResourceNamesExtensions
Expand Down
5 changes: 0 additions & 5 deletions tests/testproject/TestProject.AppHost/TestProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ private TestProgram(
.WithImageRegistry(AspireTestContainerRegistry);
IntegrationServiceABuilder = IntegrationServiceABuilder.WithReference(redis);
}
if (!resourcesToSkip.HasFlag(TestResourceNames.garnet))
{
var garnet = AppBuilder.AddGarnet("garnet");
IntegrationServiceABuilder = IntegrationServiceABuilder.WithReference(garnet);
}
if (!resourcesToSkip.HasFlag(TestResourceNames.postgres) || !resourcesToSkip.HasFlag(TestResourceNames.efnpgsql))
{
var postgresDbName = "postgresdb";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.CosmosDB" IsAspireProjectResource="false" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.EventHubs" IsAspireProjectResource="false" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" IsAspireProjectResource="false" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Garnet" IsAspireProjectResource="false" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.MongoDB" IsAspireProjectResource="false" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.MySql" IsAspireProjectResource="false" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.NodeJs" IsAspireProjectResource="false" />
Expand Down
14 changes: 0 additions & 14 deletions tests/testproject/TestProject.AppHost/aspire-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
"ConnectionStrings__tempdb": "{tempdb.connectionString}",
"ConnectionStrings__mysqldb": "{mysqldb.connectionString}",
"ConnectionStrings__redis": "{redis.connectionString}",
"ConnectionStrings__garnet": "{garnet.connectionString}",
"ConnectionStrings__valkey": "{valkey.connectionString}",
"ConnectionStrings__postgresdb": "{postgresdb.connectionString}",
"ConnectionStrings__rabbitmq": "{rabbitmq.connectionString}",
Expand Down Expand Up @@ -207,19 +206,6 @@
}
}
},
"garnet": {
"type": "container.v0",
"connectionString": "{garnet.bindings.tcp.host}:{garnet.bindings.tcp.port}",
"image": "ghcr.io/microsoft/garnet:latest",
"bindings": {
"tcp": {
"scheme": "tcp",
"protocol": "tcp",
"transport": "tcp",
"targetPort": 6379
}
}
},
"valkey": {
"type": "container.v0",
"connectionString": "{valkey.bindings.tcp.host}:{valkey.bindings.tcp.port}",
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions tests/testproject/TestProject.IntegrationServiceA/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
{
builder.AddKeyedRedisClient("redis");
}
if (!resourcesToSkip.HasFlag(TestResourceNames.garnet))
{
builder.AddKeyedRedisClient("garnet");
}
if (!resourcesToSkip.HasFlag(TestResourceNames.postgres) || !resourcesToSkip.HasFlag(TestResourceNames.efnpgsql))
{
builder.AddNpgsqlDataSource("postgresdb");
Expand Down Expand Up @@ -91,11 +87,6 @@
app.MapRedisApi();
}

if (!resourcesToSkip.HasFlag(TestResourceNames.garnet))
{
app.MapGarnetApi();
}

if (!resourcesToSkip.HasFlag(TestResourceNames.mongodb))
{
app.MapMongoDBApi();
Expand Down

0 comments on commit 7eefa05

Please sign in to comment.