diff --git a/src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExtension.cs b/src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExtension.cs index 5ed97e733..37f9f179b 100644 --- a/src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExtension.cs +++ b/src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExtension.cs @@ -30,6 +30,19 @@ public static IResourceBuilder AddGolangApp(this ID /// The optional build tags to be used when building the Golang application. /// A reference to the . public static IResourceBuilder AddGolangApp(this IDistributedApplicationBuilder builder, [ResourceName] string name, string workingDirectory, string[]? args = null, string[]? buildTags = null) + => AddGolangApp(builder, name, workingDirectory, ".", args, buildTags); + + /// + /// Adds a Golang application to the application model. Executes the executable Golang app. + /// + /// The to add the resource to. + /// The name of the resource. + /// The working directory to use for the command. If null, the working directory of the current process is used. + /// The path to the Golang package directory or source file to be executed. Use "." to execute the program in the current directory. For example, "./cmd/server". + /// The optinal arguments to be passed to the executable when it is started. + /// The optional build tags to be used when building the Golang application. + /// A reference to the . + public static IResourceBuilder AddGolangApp(this IDistributedApplicationBuilder builder, [ResourceName] string name, string workingDirectory, string executable, string[]? args = null, string[]? buildTags = null) { ArgumentNullException.ThrowIfNull(builder, nameof(builder)); ArgumentException.ThrowIfNullOrWhiteSpace(name, nameof(name)); @@ -43,7 +56,7 @@ public static IResourceBuilder AddGolangApp(this ID allArgs.Add(string.Join(",", buildTags)); } - allArgs.Add("."); + allArgs.Add(executable); if (args is { Length: > 0 }) { diff --git a/tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/ResourceCreationTests.cs b/tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/ResourceCreationTests.cs index b0a0aff38..c0ed2d211 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/ResourceCreationTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/ResourceCreationTests.cs @@ -58,4 +58,34 @@ public async Task GolangAppWithBuildTagsAsync() } ); } + + + [Fact] + public async Task GolangAppWithExecutableAsync() + { + var builder = DistributedApplication.CreateBuilder(); + + builder.AddGolangApp("golang", "../../examples/golang/gin-api", "./cmd/server"); + + using var app = builder.Build(); + + var appModel = app.Services.GetRequiredService(); + + var resource = appModel.Resources.OfType().SingleOrDefault(); + + Assert.NotNull(resource); + + var args = await resource.GetArgumentValuesAsync(); + Assert.Collection( + args, + arg => + { + Assert.Equal("run", arg); + }, + arg => + { + Assert.Equal("./cmd/server", arg); + } + ); + } } \ No newline at end of file