Skip to content

Commit a2fb516

Browse files
committed
Move integration tests over to aspire
1 parent a4e0470 commit a2fb516

File tree

8 files changed

+24
-92
lines changed

8 files changed

+24
-92
lines changed

src/Elastic.Documentation.ServiceDefaults/AppDefaultsExtensions.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ public static TBuilder AddAppDefaults<TBuilder>(this TBuilder builder, ref strin
3636
ProcessCommandLineArguments(ref args, ref logLevel);
3737

3838
var services = builder.Services;
39-
_ = services.AddLogging(x => x
40-
.ClearProviders()
41-
.SetMinimumLevel(logLevel).AddConsole(c => c.FormatterName = "condensed")
42-
);
43-
4439
_ = services
4540
.AddGitHubActionsCore()
4641
.AddSingleton<DiagnosticsChannel>()
@@ -58,7 +53,7 @@ public static TBuilder AddAppDefaults<TBuilder>(this TBuilder builder, ref strin
5853
.AddConsole(c => c.FormatterName = "condensed")
5954
);
6055

61-
return builder;
56+
return builder.AddServiceDefaults();
6257
}
6358

6459
private static void ProcessCommandLineArguments(ref string[] args, ref LogLevel defaultLogLevel)

src/tooling/docs-assembler/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
.AddAppDefaults(ref args, (s, p) =>
2020
{
2121
_ = s.AddSingleton(AssemblyConfiguration.Create(p));
22-
})
23-
.AddServiceDefaults();
22+
});
2423

2524
var app = builder.ToConsoleAppBuilder();
2625

src/tooling/docs-builder/Http/DocumentationWebHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public DocumentationWebHost(ILoggerFactory logFactory, string? path, int port, I
3535
{
3636
_writeFileSystem = writeFs;
3737
var builder = WebApplication.CreateSlimBuilder();
38-
_ = builder.AddAppDefaults().AddServiceDefaults();
38+
_ = builder.AddAppDefaults();
3939

4040
_ = builder.Logging
4141
.AddFilter("Microsoft.AspNetCore.Hosting.Diagnostics", LogLevel.Error)

src/tooling/docs-builder/Http/StaticWebHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public StaticWebHost(int port)
2626
ContentRootPath = contentRoot
2727
});
2828

29-
_ = builder.AddAppDefaults().AddServiceDefaults();
29+
_ = builder.AddAppDefaults();
3030

3131
_ = builder.Logging
3232
.AddFilter("Microsoft.AspNetCore.Hosting.Diagnostics", LogLevel.Error)

src/tooling/docs-builder/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
using Microsoft.Extensions.Logging;
1313

1414
var builder = Host.CreateApplicationBuilder()
15-
.AddAppDefaults(ref args)
16-
.AddServiceDefaults();
15+
.AddAppDefaults(ref args);
1716

1817
var app = builder.ToConsoleAppBuilder();
1918

tests-integration/Elastic.Assembler.IntegrationTests/AssembleFixture.cs

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,9 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Collections.ObjectModel;
6-
using System.IO.Abstractions;
5+
using Aspire.Hosting;
76
using Aspire.Hosting.Testing;
8-
using Documentation.Assembler;
9-
using Documentation.Assembler.Building;
10-
using Documentation.Assembler.Legacy;
11-
using Documentation.Assembler.Navigation;
12-
using Documentation.Assembler.Sourcing;
13-
using Documentation.Builder.Http;
14-
using Elastic.Documentation.Configuration;
15-
using Elastic.Documentation.Configuration.Assembler;
16-
using Elastic.Documentation.Configuration.Versions;
17-
using Elastic.Documentation.LegacyDocs;
18-
using Elastic.Documentation.Tooling;
19-
using Elastic.Documentation.Tooling.Diagnostics.Console;
20-
using Microsoft.Extensions.Logging;
217
using FluentAssertions;
22-
using Xunit;
238

249
[assembly: CaptureConsole, AssemblyFixture(typeof(Elastic.Assembler.IntegrationTests.AssembleFixture))]
2510

@@ -28,85 +13,37 @@ namespace Elastic.Assembler.IntegrationTests;
2813

2914
public class AssembleFixture : IAsyncLifetime
3015
{
31-
private static IFileSystem FileSystem { get; } = new FileSystem();
32-
public ConfigurationFileProvider ConfigurationFileProvider { get; } = new(FileSystem);
33-
public StaticWebHost WebsiteHost { get; private set; } = null!;
34-
public Task WebsiteRunning { get; private set; } = null!;
16+
public DistributedApplication DistributedApplication { get; private set; } = null!;
3517

3618
/// <inheritdoc />
37-
public async ValueTask DisposeAsync()
19+
public async ValueTask InitializeAsync()
3820
{
39-
GC.SuppressFinalize(this);
40-
await WebsiteHost.StopAsync(TestContext.Current.CancellationToken);
21+
var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.Elastic_Documentation_Aspire>();
22+
DistributedApplication = await builder.BuildAsync();
23+
await DistributedApplication.StartAsync();
4124
}
4225

4326
/// <inheritdoc />
44-
public async ValueTask InitializeAsync()
27+
public async ValueTask DisposeAsync()
4528
{
46-
//var builder = await DistributedApplicationTestingBuilder.CreateAsync([]);
47-
var ctx = TestContext.Current.CancellationToken;
48-
var logFactory = LoggerFactory.Create(builder =>
49-
{
50-
_ = builder.AddConsole();
51-
});
52-
await using var collector = new ConsoleDiagnosticsCollector(logFactory, null).StartAsync(ctx);
53-
54-
var assemblyConfiguration = AssemblyConfiguration.Create(ConfigurationFileProvider);
55-
var versionsConfig = ConfigurationFileProvider.CreateVersionConfiguration();
56-
57-
var assembleContext = new AssembleContext(assemblyConfiguration, ConfigurationFileProvider, "dev", collector, FileSystem, FileSystem, null, null);
58-
var cloner = new AssemblerRepositorySourcer(logFactory, assembleContext);
59-
60-
_ = await cloner.CloneAll(false, ctx);
61-
62-
_ = GlobalNavigationFile.ValidatePathPrefixes(assembleContext);
63-
64-
var checkoutResult = cloner.GetAll();
65-
var checkouts = checkoutResult.Checkouts.ToArray();
66-
67-
if (checkouts.Length == 0)
68-
throw new Exception("No checkouts found");
69-
70-
var assembleSources = await AssembleSources.AssembleAsync(logFactory, assembleContext, checkouts, versionsConfig, ctx);
71-
var navigationFile = new GlobalNavigationFile(assembleContext, assembleSources);
72-
73-
var navigation = new GlobalNavigation(assembleSources, navigationFile);
74-
75-
var pathProvider = new GlobalNavigationPathProvider(navigationFile, assembleSources, assembleContext);
76-
var htmlWriter = new GlobalNavigationHtmlWriter(logFactory, navigation, collector);
77-
var legacyPageChecker = new LegacyPageChecker();
78-
var historyMapper = new PageLegacyUrlMapper(legacyPageChecker, assembleSources.HistoryMappings);
79-
80-
var exporters = new HashSet<ExportOption>([ExportOption.Html, ExportOption.Configuration]);
81-
var builder = new AssemblerBuilder(logFactory, assembleContext, navigation, htmlWriter, pathProvider, historyMapper);
82-
await builder.BuildAllAsync(assembleSources.AssembleSets, exporters, ctx);
83-
84-
await cloner.WriteLinkRegistrySnapshot(checkoutResult.LinkRegistrySnapshot, ctx);
85-
86-
var redirectsPath = Path.Combine(assembleContext.OutputDirectory.FullName, "redirects.json");
87-
88-
var sitemapBuilder = new SitemapBuilder(navigation.NavigationItems, assembleContext.WriteFileSystem, assembleContext.OutputDirectory);
89-
sitemapBuilder.Generate();
90-
91-
await collector.StopAsync(ctx);
92-
93-
WebsiteHost = new StaticWebHost(4001);
94-
WebsiteRunning = WebsiteHost.RunAsync(ctx);
95-
_ = await WebsiteHost.WaitForAppStartup(ctx);
29+
await DistributedApplication.StopAsync();
30+
await DistributedApplication.DisposeAsync();
31+
GC.SuppressFinalize(this);
9632
}
9733

34+
9835
}
9936

10037
public class DatabaseTestClass1(AssembleFixture fixture)
10138
{
10239
[Fact]
10340
public async Task X()
10441
{
105-
using var client = new HttpClient { BaseAddress = new Uri("http://localhost:4001") };
42+
_ = await fixture.DistributedApplication.ResourceNotifications
43+
.WaitForResourceHealthyAsync("DocsBuilderServeStatic", cancellationToken: TestContext.Current.CancellationToken);
44+
var client = fixture.DistributedApplication.CreateHttpClient("DocsBuilderServeStatic", "http");
10645
var root = await client.GetStringAsync("/", TestContext.Current.CancellationToken);
107-
Console.WriteLine(root);
108-
109-
fixture.Should().NotBeNull();
46+
_ = root.Should().NotBeNullOrEmpty();
11047
}
11148

11249

tests-integration/Elastic.Assembler.IntegrationTests/Elastic.Assembler.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ProjectReference Include="..\..\src\Elastic.Documentation\Elastic.Documentation.csproj" />
1111
<ProjectReference Include="..\..\src\tooling\docs-assembler\docs-assembler.csproj" />
1212
<ProjectReference Include="..\..\src\tooling\docs-builder\docs-builder.csproj" />
13+
<ProjectReference Include="..\Elastic.Documentation.Aspire\Elastic.Documentation.Aspire.csproj" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

tests-integration/Elastic.Documentation.Aspire/AppHost.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
var buildAll = builder.AddProject<Projects.docs_assembler>("DocsAssemblerBuildAll").WithArgs("repo", "build-all").WaitForCompletion(cloneAll);
1010

1111
var serveStatic = builder.AddProject<Projects.docs_builder>("DocsBuilderServeStatic")
12-
.WithHttpEndpoint(name: "serve-static", port: 4000, isProxied: false)
12+
.WithHttpEndpoint(port: 4000, isProxied: false)
1313
.WithArgs("serve-static")
14+
.WithHttpHealthCheck("/", 200)
1415
.WaitForCompletion(buildAll);
1516

16-
builder.AddElasticsearch("elasticsearch");
17+
//builder.AddElasticsearch("elasticsearch");
1718

1819
builder.Build().Run();

0 commit comments

Comments
 (0)