|
| 1 | +using Aspire.Components.Common.Tests; |
1 | 2 | using Aspire.Hosting; |
2 | 3 | using Aspire.Hosting.Utils; |
3 | | -using Microsoft.Extensions.FileProviders; |
4 | | -using Microsoft.Extensions.Hosting; |
| 4 | +using Xunit.Abstractions; |
5 | 5 |
|
6 | 6 | namespace CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests; |
7 | 7 |
|
8 | | -public class ResourceCreationTests |
| 8 | +public class ResourceCreationTests(ITestOutputHelper testOutputHelper) |
9 | 9 | { |
10 | 10 | [Fact] |
11 | 11 | public void CanCreateTheCollectorResource() |
12 | 12 | { |
13 | | - var builder = DistributedApplication.CreateBuilder(); |
| 13 | + var builder = TestDistributedApplicationBuilder.Create(); |
14 | 14 |
|
15 | 15 | builder.AddOpenTelemetryCollector("collector") |
16 | 16 | .WithConfig("./config.yaml") |
@@ -150,33 +150,33 @@ public void CanDisableBothEndpoints() |
150 | 150 | } |
151 | 151 |
|
152 | 152 | [Fact] |
153 | | - public void ContainerHasAspireEnvironmentVariables() |
| 153 | + [RequiresDocker] |
| 154 | + public async Task ContainerHasAspireEnvironmentVariables() |
154 | 155 | { |
155 | | - var builder = DistributedApplication.CreateBuilder(); |
| 156 | + using var builder = TestDistributedApplicationBuilder.Create() |
| 157 | + .WithTestAndResourceLogging(testOutputHelper); |
| 158 | + builder.Configuration["APPHOST:ContainerHostname"] = "what.ever"; |
156 | 159 |
|
157 | | - builder.AddOpenTelemetryCollector("collector") |
| 160 | + var collector = builder.AddOpenTelemetryCollector("collector") |
158 | 161 | .WithAppForwarding(); |
159 | 162 |
|
160 | 163 | using var app = builder.Build(); |
161 | 164 | var appModel = app.Services.GetRequiredService<DistributedApplicationModel>(); |
162 | | - var collectorResource = appModel.Resources.OfType<OpenTelemetryCollectorResource>().SingleOrDefault(); |
163 | | - Assert.NotNull(collectorResource); |
164 | 165 |
|
165 | | - var envs = collectorResource.Annotations.OfType<EnvironmentCallbackAnnotation>().ToList(); |
166 | | - Assert.NotEmpty(envs); |
| 166 | + var resourceNotificationService = app.Services.GetRequiredService<ResourceNotificationService>(); |
167 | 167 |
|
168 | | - var context = new EnvironmentCallbackContext(new DistributedApplicationExecutionContext(new DistributedApplicationExecutionContextOptions(DistributedApplicationOperation.Run))); |
169 | | - foreach (var env in envs) |
170 | | - { |
171 | | - env.Callback(context); |
172 | | - } |
| 168 | + await app.StartAsync(); |
| 169 | + await resourceNotificationService.WaitForResourceHealthyAsync(collector.Resource.Name); |
| 170 | + |
| 171 | + Assert.True(resourceNotificationService.TryGetCurrentState(collector.Resource.Name, out var resourceEvent)); |
| 172 | + |
| 173 | + var envVars = resourceEvent.Snapshot.EnvironmentVariables.ToDictionary(k => k.Name, v => v.Value); |
173 | 174 |
|
174 | | - Assert.Contains("ASPIRE_ENDPOINT", context.EnvironmentVariables.Keys); |
175 | | - Assert.Contains("ASPIRE_API_KEY", context.EnvironmentVariables.Keys); |
| 175 | + var endpoint = Assert.Contains("ASPIRE_ENDPOINT", envVars); |
| 176 | + var apiKey = Assert.Contains("ASPIRE_API_KEY", envVars); |
176 | 177 |
|
177 | | - var url = Assert.IsType<HostUrl>(context.EnvironmentVariables["ASPIRE_ENDPOINT"]); |
178 | | - Assert.Equal("http://localhost:18889", url.Url); |
179 | | - Assert.NotNull(context.EnvironmentVariables["ASPIRE_API_KEY"]); |
| 178 | + Assert.Equal($"http://what.ever:18889", endpoint); |
| 179 | + Assert.NotNull(apiKey); |
180 | 180 | } |
181 | 181 |
|
182 | 182 | [Fact] |
|
0 commit comments