From 4d4019d25bb8c76cb6e0aa310087f8d6c654f426 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 18 Feb 2025 15:53:46 -0800 Subject: [PATCH] Avoid unnecessary containers in Aspire.Hosting.Testing.Tests --- .../TestingBuilderTests.cs | 11 +++++------ .../TestingFactoryTests.cs | 8 +------- .../TestingAppHost1.AppHost/Program.cs | 7 +++++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs index 0c43d0751cf..9a14fed08b7 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs @@ -125,10 +125,10 @@ public async Task HasEndPoints(bool genericEntryPoint) Assert.NotNull(workerEndpoint); Assert.True(workerEndpoint.Host.Length > 0); - // Get a connection string from a resource - var pgConnectionString = await app.GetConnectionStringAsync("postgres1"); - Assert.NotNull(pgConnectionString); - Assert.True(pgConnectionString.Length > 0); + // Get a connection string + var connectionString = await app.GetConnectionStringAsync("cs"); + Assert.NotNull(connectionString); + Assert.True(connectionString.Length > 0); } [Theory] @@ -146,7 +146,6 @@ public async Task CanGetResources(bool genericEntryPoint) // Ensure that the resource which we added is present in the model. var appModel = app.Services.GetRequiredService(); - Assert.Contains(appModel.GetContainerResources(), c => c.Name == "redis1"); Assert.Contains(appModel.GetProjectResources(), p => p.Name == "myworker1"); } @@ -500,7 +499,7 @@ public async Task StartAsyncAbandonedAfterHang() try { var builder = await DistributedApplicationTestingBuilder.CreateAsync( - ["--wait-for-healthy"], + ["--wait-for-healthy", "--add-redis"], cts.Token).WaitAsync(cts.Token); // Make the redis container hang forever. diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs index f985925f1cb..3b1d047f271 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs @@ -17,17 +17,12 @@ public class TestingFactoryTests(DistributedApplicationFixture 0); - - // Get a connection string from a resource - var pgConnectionString = await _app.GetConnectionStringAsync("postgres1"); - Assert.NotNull(pgConnectionString); - Assert.True(pgConnectionString.Length > 0); } [Fact] @@ -44,7 +39,6 @@ public async Task CanGetConnectionStringFromAddConnectionString() public void CanGetResources() { var appModel = _app.Services.GetRequiredService(); - Assert.Contains(appModel.GetContainerResources(), c => c.Name == "redis1"); Assert.Contains(appModel.GetProjectResources(), p => p.Name == "myworker1"); } diff --git a/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs b/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs index 018d47e6b0f..cf9a8d3d0d2 100644 --- a/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs +++ b/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs @@ -10,7 +10,11 @@ builder.Configuration["ConnectionStrings:cs"] = "testconnection"; builder.AddConnectionString("cs"); -builder.AddRedis("redis1"); +if (args.Contains("--add-redis")) +{ + builder.AddRedis("redis1"); +} + var webApp = builder.AddProject("mywebapp1") .WithEnvironment("APP_HOST_ARG", builder.Configuration["APP_HOST_ARG"]) .WithEnvironment("LAUNCH_PROFILE_VAR_FROM_APP_HOST", builder.Configuration["LAUNCH_PROFILE_VAR_FROM_APP_HOST"]); @@ -22,7 +26,6 @@ builder.AddProject("myworker1") .WithEndpoint(name: "myendpoint1", env: "myendpoint1_port"); -builder.AddPostgres("postgres1"); if (args.Contains("--add-unknown-container")) {