-
Notifications
You must be signed in to change notification settings - Fork 931
Set default OutputPath and add IntermediateOutputPath at PipelineContext level #12414
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
adf5bc4
Initial plan
Copilot 4876719
Fix default output path handling for deploy command
Copilot 5ce261a
Unify output path handling across Azure, Docker, and Kubernetes
Copilot 7a481ce
Set default OutputPath at PipelineContext level and add IntermediateO…
Copilot 368f679
Use Directory.CreateTempSubdirectory, remove PublishingContextUtils, …
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 209 additions & 0 deletions
209
tests/Aspire.Hosting.Kubernetes.Tests/PublishingContextUtilsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #pragma warning disable ASPIRECOMPUTE001 | ||
| #pragma warning disable ASPIREPUBLISHERS001 | ||
| #pragma warning disable ASPIREPIPELINES001 | ||
|
|
||
| using Aspire.Hosting.ApplicationModel; | ||
| using Aspire.Hosting.Pipelines; | ||
| using Aspire.Hosting.Utils; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
|
|
||
| namespace Aspire.Hosting.Kubernetes.Tests; | ||
|
|
||
| public class PublishingContextUtilsTests | ||
| { | ||
| [Fact] | ||
| public void GetEnvironmentOutputPath_WithNullOutputPath_ReturnsFallbackPath() | ||
| { | ||
| // Arrange | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
| var app = builder.Build(); | ||
| var model = app.Services.GetRequiredService<DistributedApplicationModel>(); | ||
| var executionContext = app.Services.GetRequiredService<DistributedApplicationExecutionContext>(); | ||
|
|
||
| var pipelineContext = new PipelineContext( | ||
| model, | ||
| executionContext, | ||
| app.Services, | ||
| NullLogger.Instance, | ||
| CancellationToken.None, | ||
| outputPath: null); | ||
|
|
||
| var stepContext = new PipelineStepContext | ||
| { | ||
| PipelineContext = pipelineContext, | ||
| ReportingStep = new TestReportingStep() | ||
| }; | ||
|
|
||
| var environment = new TestComputeEnvironmentResource("test-env"); | ||
|
|
||
| // Act | ||
| var outputPath = PublishingContextUtils.GetEnvironmentOutputPath(stepContext, environment); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(outputPath); | ||
| Assert.EndsWith("aspire-output", outputPath); | ||
| Assert.Contains(Environment.CurrentDirectory, outputPath); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetEnvironmentOutputPath_WithExplicitOutputPath_ReturnsExplicitPath() | ||
| { | ||
| // Arrange | ||
| var explicitPath = "/tmp/custom-output"; | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
| var app = builder.Build(); | ||
| var model = app.Services.GetRequiredService<DistributedApplicationModel>(); | ||
| var executionContext = app.Services.GetRequiredService<DistributedApplicationExecutionContext>(); | ||
|
|
||
| var pipelineContext = new PipelineContext( | ||
| model, | ||
| executionContext, | ||
| app.Services, | ||
| NullLogger.Instance, | ||
| CancellationToken.None, | ||
| outputPath: explicitPath); | ||
|
|
||
| var stepContext = new PipelineStepContext | ||
| { | ||
| PipelineContext = pipelineContext, | ||
| ReportingStep = new TestReportingStep() | ||
| }; | ||
|
|
||
| var environment = new TestComputeEnvironmentResource("test-env"); | ||
|
|
||
| // Act | ||
| var outputPath = PublishingContextUtils.GetEnvironmentOutputPath(stepContext, environment); | ||
|
|
||
| // Assert | ||
| Assert.Equal(explicitPath, outputPath); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetEnvironmentOutputPath_WithMultipleEnvironments_AppendsEnvironmentName() | ||
| { | ||
| // Arrange | ||
| var explicitPath = "/tmp/custom-output"; | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
|
|
||
| var env1 = new TestComputeEnvironmentResource("env1"); | ||
| var env2 = new TestComputeEnvironmentResource("env2"); | ||
| builder.AddResource(env1); | ||
| builder.AddResource(env2); | ||
|
|
||
| var app = builder.Build(); | ||
| var model = app.Services.GetRequiredService<DistributedApplicationModel>(); | ||
| var executionContext = app.Services.GetRequiredService<DistributedApplicationExecutionContext>(); | ||
|
|
||
| var pipelineContext = new PipelineContext( | ||
| model, | ||
| executionContext, | ||
| app.Services, | ||
| NullLogger.Instance, | ||
| CancellationToken.None, | ||
| outputPath: explicitPath); | ||
|
|
||
| var stepContext = new PipelineStepContext | ||
| { | ||
| PipelineContext = pipelineContext, | ||
| ReportingStep = new TestReportingStep() | ||
| }; | ||
|
|
||
| // Act | ||
| var outputPath1 = PublishingContextUtils.GetEnvironmentOutputPath(stepContext, env1); | ||
| var outputPath2 = PublishingContextUtils.GetEnvironmentOutputPath(stepContext, env2); | ||
|
|
||
| // Assert | ||
| Assert.Equal(Path.Combine(explicitPath, "env1"), outputPath1); | ||
| Assert.Equal(Path.Combine(explicitPath, "env2"), outputPath2); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetEnvironmentOutputPath_WithMultipleEnvironmentsAndNullOutputPath_UsesFallbackAndAppendsEnvironmentName() | ||
| { | ||
| // Arrange | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
|
|
||
| var env1 = new TestComputeEnvironmentResource("env1"); | ||
| var env2 = new TestComputeEnvironmentResource("env2"); | ||
| builder.AddResource(env1); | ||
| builder.AddResource(env2); | ||
|
|
||
| var app = builder.Build(); | ||
| var model = app.Services.GetRequiredService<DistributedApplicationModel>(); | ||
| var executionContext = app.Services.GetRequiredService<DistributedApplicationExecutionContext>(); | ||
|
|
||
| var pipelineContext = new PipelineContext( | ||
| model, | ||
| executionContext, | ||
| app.Services, | ||
| NullLogger.Instance, | ||
| CancellationToken.None, | ||
| outputPath: null); | ||
|
|
||
| var stepContext = new PipelineStepContext | ||
| { | ||
| PipelineContext = pipelineContext, | ||
| ReportingStep = new TestReportingStep() | ||
| }; | ||
|
|
||
| // Act | ||
| var outputPath1 = PublishingContextUtils.GetEnvironmentOutputPath(stepContext, env1); | ||
| var outputPath2 = PublishingContextUtils.GetEnvironmentOutputPath(stepContext, env2); | ||
|
|
||
| // Assert | ||
| var expectedBasePath = Path.Combine(Environment.CurrentDirectory, "aspire-output"); | ||
| Assert.Equal(Path.Combine(expectedBasePath, "env1"), outputPath1); | ||
| Assert.Equal(Path.Combine(expectedBasePath, "env2"), outputPath2); | ||
| } | ||
|
|
||
| private sealed class TestComputeEnvironmentResource : Resource, IComputeEnvironmentResource | ||
| { | ||
| public TestComputeEnvironmentResource(string name) : base(name) | ||
| { | ||
| } | ||
|
|
||
| public ReferenceExpression GetHostAddressExpression(EndpointReference endpointReference) | ||
| { | ||
| return ReferenceExpression.Create($"{endpointReference.Resource.Name}"); | ||
| } | ||
| } | ||
|
|
||
| private sealed class TestReportingStep : IReportingStep | ||
| { | ||
| public ValueTask DisposeAsync() => ValueTask.CompletedTask; | ||
|
|
||
| public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, string message, bool enableMarkdown = false) | ||
| { | ||
| // No-op | ||
| } | ||
|
|
||
| public Task<IReportingTask> CreateTaskAsync(string statusText, CancellationToken cancellationToken = default) | ||
| { | ||
| return Task.FromResult<IReportingTask>(new TestReportingTask()); | ||
| } | ||
|
|
||
| public Task CompleteAsync(string completionText, CompletionState completionState = CompletionState.Completed, CancellationToken cancellationToken = default) | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
|
|
||
| private sealed class TestReportingTask : IReportingTask | ||
| { | ||
| public ValueTask DisposeAsync() => ValueTask.CompletedTask; | ||
|
|
||
| public Task CompleteAsync(string? completionMessage = null, CompletionState completionState = CompletionState.Completed, CancellationToken cancellationToken = default) | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| public Task UpdateAsync(string statusText, CancellationToken cancellationToken = default) | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this test file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit 5ce261a.