Skip to content

Commit 245ebdc

Browse files
authored
Avoid unnecessary containers in Aspire.Hosting.Testing.Tests (#7666)
1 parent e6aef9b commit 245ebdc

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ public async Task HasEndPoints(bool genericEntryPoint)
125125
Assert.NotNull(workerEndpoint);
126126
Assert.True(workerEndpoint.Host.Length > 0);
127127

128-
// Get a connection string from a resource
129-
var pgConnectionString = await app.GetConnectionStringAsync("postgres1");
130-
Assert.NotNull(pgConnectionString);
131-
Assert.True(pgConnectionString.Length > 0);
128+
// Get a connection string
129+
var connectionString = await app.GetConnectionStringAsync("cs");
130+
Assert.NotNull(connectionString);
131+
Assert.True(connectionString.Length > 0);
132132
}
133133

134134
[Theory]
@@ -146,7 +146,6 @@ public async Task CanGetResources(bool genericEntryPoint)
146146

147147
// Ensure that the resource which we added is present in the model.
148148
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
149-
Assert.Contains(appModel.GetContainerResources(), c => c.Name == "redis1");
150149
Assert.Contains(appModel.GetProjectResources(), p => p.Name == "myworker1");
151150
}
152151

@@ -500,7 +499,7 @@ public async Task StartAsyncAbandonedAfterHang()
500499
try
501500
{
502501
var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.TestingAppHost1_AppHost>(
503-
["--wait-for-healthy"],
502+
["--wait-for-healthy", "--add-redis"],
504503
cts.Token).WaitAsync(cts.Token);
505504

506505
// Make the redis container hang forever.

tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ public class TestingFactoryTests(DistributedApplicationFixture<Projects.TestingA
1717

1818
[Fact]
1919
[RequiresDocker]
20-
public async Task HasEndPoints()
20+
public void HasEndPoints()
2121
{
2222
// Get an endpoint from a resource
2323
var workerEndpoint = _app.GetEndpoint("myworker1", "myendpoint1");
2424
Assert.NotNull(workerEndpoint);
2525
Assert.True(workerEndpoint.Host.Length > 0);
26-
27-
// Get a connection string from a resource
28-
var pgConnectionString = await _app.GetConnectionStringAsync("postgres1");
29-
Assert.NotNull(pgConnectionString);
30-
Assert.True(pgConnectionString.Length > 0);
3126
}
3227

3328
[Fact]
@@ -44,7 +39,6 @@ public async Task CanGetConnectionStringFromAddConnectionString()
4439
public void CanGetResources()
4540
{
4641
var appModel = _app.Services.GetRequiredService<DistributedApplicationModel>();
47-
Assert.Contains(appModel.GetContainerResources(), c => c.Name == "redis1");
4842
Assert.Contains(appModel.GetProjectResources(), p => p.Name == "myworker1");
4943
}
5044

tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
builder.Configuration["ConnectionStrings:cs"] = "testconnection";
1111

1212
builder.AddConnectionString("cs");
13-
builder.AddRedis("redis1");
13+
if (args.Contains("--add-redis"))
14+
{
15+
builder.AddRedis("redis1");
16+
}
17+
1418
var webApp = builder.AddProject<Projects.TestingAppHost1_MyWebApp>("mywebapp1")
1519
.WithEnvironment("APP_HOST_ARG", builder.Configuration["APP_HOST_ARG"])
1620
.WithEnvironment("LAUNCH_PROFILE_VAR_FROM_APP_HOST", builder.Configuration["LAUNCH_PROFILE_VAR_FROM_APP_HOST"]);
@@ -22,7 +26,6 @@
2226

2327
builder.AddProject<Projects.TestingAppHost1_MyWorker>("myworker1")
2428
.WithEndpoint(name: "myendpoint1", env: "myendpoint1_port");
25-
builder.AddPostgres("postgres1");
2629

2730
if (args.Contains("--add-unknown-container"))
2831
{

0 commit comments

Comments
 (0)