Skip to content
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
6 changes: 0 additions & 6 deletions tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
<ProjectReference Include="..\..\src\Aspire.Hosting\Aspire.Hosting.csproj" />
<ProjectReference Include="..\..\src\Aspire.Cli\Aspire.Cli.csproj" />
<ProjectReference Include="..\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj" />
<ProjectReference Include="..\Aspire.TestUtilities\Aspire.TestUtilities.csproj" IsAspireProjectResource="false" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\playground\DatabaseMigration\DatabaseMigration.ApiService\DatabaseMigration.ApiService.csproj" />
<ProjectReference Include="..\..\playground\DatabaseMigration\DatabaseMigration.AppHost\DatabaseMigration.AppHost.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
259 changes: 0 additions & 259 deletions tests/Aspire.Cli.Tests/E2E/ExecTests.cs

This file was deleted.

67 changes: 67 additions & 0 deletions tests/Aspire.Hosting.Tests/Backchannel/Exec/ExecTestsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Backchannel;
using Aspire.Hosting.Testing;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.DependencyInjection;

namespace Aspire.Hosting.Tests.Backchannel.Exec;

public abstract class ExecTestsBase(ITestOutputHelper outputHelper)
{
protected readonly ITestOutputHelper _outputHelper = outputHelper;

/// <summary>
/// Performs an `exec` against the apphost,
/// collecting the logs of the `exec` resource apphost is being run against.
///
/// Also awaits the app startup. It has to be built before running this method.
/// </summary>
internal async Task<List<CommandOutput>> ExecWithLogCollectionAsync(
DistributedApplication app,
int timeoutSec = 30)
{
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSec));

var appHostRpcTarget = app.Services.GetRequiredService<AppHostRpcTarget>();
var outputStream = appHostRpcTarget.ExecAsync(cts.Token);

var logs = new List<CommandOutput>();
var startTask = app.StartAsync(cts.Token);
await foreach (var message in outputStream)
{
var logLevel = message.IsErrorMessage ? "error" : "info";
var log = $"Received output: #{message.LineNumber} [level={logLevel}] [type={message.Type}] {message.Text}";

logs.Add(message);
_outputHelper.WriteLine(log);
}

await startTask;
return logs;
}

internal static void AssertLogsContain(List<CommandOutput> logs, params string[] expectedLogMessages)
{
if (expectedLogMessages.Length == 0)
{
Assert.Empty(logs);
return;
}

foreach (var expectedMessage in expectedLogMessages)
{
var logFound = logs.Any(x => x.Text.Contains(expectedMessage));
Assert.True(logFound, $"Expected log message '{expectedMessage}' not found in logs.");
}
}

protected IDistributedApplicationTestingBuilder PrepareBuilder(string[] args)
{
var builder = TestDistributedApplicationBuilder.Create(_outputHelper, args).WithTestAndResourceLogging(_outputHelper);
builder.Configuration[KnownConfigNames.UnixSocketPath] = UnixSocketHelper.GetBackchannelSocketPath();
return builder;
}
}
Loading
Loading