Skip to content

Allow DistributedApplicationTestingBuilder to override WithLifetime(ContainerLifetime.Persistent) #6850

@yarseyah

Description

@yarseyah

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Whilst using the DistributedApplicationTestingBuilder for testing, when the AppHost has one or more WithLifetime set to persist containers, an increasing number of separate containers are generated.

The unit tests seem to generate a completely new set of resources, e.g. the first below is when running in the IDE, and the next two correspond to two test runs.

Image

var fixturesDb = builder.AddRedis("fixtures")
    .WithPersistence()
    .WithDataVolume()
    .WithRedisInsight(
        cfg =>
        {
            cfg.WithLifetime(ContainerLifetime.Persistent);
        },
        "redis-insight")
    .WithLifetime(ContainerLifetime.Persistent);

Keeping the containers corresponding to a unit test seems to be undesirable - additionally, if I have designed the unit tests to be re-runnable on a persisted database, it would help massively not to spin up those resources again.

Describe the solution you'd like

It would be useful to inform DistributedApplicationTestingBuilder how to override ContainerLifetime.Persistent or reuse the same containers without adding the additional 'test-run' to the resource name.

Additional context

No response

Metadata

Metadata

Assignees

Labels

area-app-testingIssues pertaining to the APIs in Aspire.Hosting.Testing

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions