Skip to content

Avoid unnecessary containers in Aspire.Hosting.Testing.Tests #7666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<DistributedApplicationModel>();
Assert.Contains(appModel.GetContainerResources(), c => c.Name == "redis1");
Assert.Contains(appModel.GetProjectResources(), p => p.Name == "myworker1");
}

Expand Down Expand Up @@ -500,7 +499,7 @@ public async Task StartAsyncAbandonedAfterHang()
try
{
var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.TestingAppHost1_AppHost>(
["--wait-for-healthy"],
["--wait-for-healthy", "--add-redis"],
cts.Token).WaitAsync(cts.Token);

// Make the redis container hang forever.
Expand Down
8 changes: 1 addition & 7 deletions tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ public class TestingFactoryTests(DistributedApplicationFixture<Projects.TestingA

[Fact]
[RequiresDocker]
public async Task HasEndPoints()
public void HasEndPoints()
{
// Get an endpoint from a resource
var workerEndpoint = _app.GetEndpoint("myworker1", "myendpoint1");
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the next test already exercises the GetConnectionStringAsync method

}

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

Expand Down
7 changes: 5 additions & 2 deletions tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Projects.TestingAppHost1_MyWebApp>("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"]);
Expand All @@ -22,7 +26,6 @@

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

if (args.Contains("--add-unknown-container"))
{
Expand Down