Skip to content
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

[tests] Fix some flaky tests in Aspire.Hosting.Azure.Tests #5187

Merged
merged 2 commits into from
Aug 6, 2024
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
3 changes: 2 additions & 1 deletion tests/Aspire.Hosting.Tests/Schema/SchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public void ValidateApplicationSamples(string testCaseName, Action<IDistributedA
{
_ = testCaseName;

var builder = TestDistributedApplicationBuilder.Create(["--publisher", "manifest", "--output-path", "not-used.json"]);
string manifestDir = Directory.CreateTempSubdirectory(testCaseName).FullName;
var builder = TestDistributedApplicationBuilder.Create(["--publisher", "manifest", "--output-path", Path.Combine(manifestDir, "not-used.json")]);
builder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, JsonDocumentManifestPublisher>("manifest");
configurator(builder);

Expand Down
7 changes: 4 additions & 3 deletions tests/Aspire.Hosting.Tests/Utils/ManifestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ public static async Task<JsonNode[]> GetManifests(IResource[] resources)

public static async Task<(JsonNode ManifestNode, string BicepText)> GetManifestWithBicep(IResource resource)
{
var manifestNode = await GetManifest(resource);
string manifestDir = Directory.CreateTempSubdirectory(resource.Name).FullName;
var manifestNode = await GetManifest(resource, manifestDir);

if (!manifestNode.AsObject().TryGetPropertyValue("path", out var pathNode))
{
throw new ArgumentException("Specified resource does not contain a path property.", nameof(resource));
}

if (pathNode?.ToString() is not { } path || !File.Exists(path))
if (pathNode?.ToString() is not { } path || !File.Exists(Path.Combine(manifestDir, path)))
{
throw new ArgumentException("Path node in resource is null, empty, or does not exist.", nameof(resource));
}

var bicepText = await File.ReadAllTextAsync(path);
var bicepText = await File.ReadAllTextAsync(Path.Combine(manifestDir, path));
return (manifestNode, bicepText);
}
}