Skip to content

Commit 1558644

Browse files
committed
Initial infra work for assembler integration tests
1 parent ad418ac commit 1558644

File tree

12 files changed

+229
-103
lines changed

12 files changed

+229
-103
lines changed

Directory.Packages.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<!-- Enable central package management, https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
44
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
55
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
68
</PropertyGroup>
79
<ItemGroup>
810
<GlobalPackageReference Include="MinVer" Version="6.0.0" PrivateAssets="All" />
@@ -19,8 +21,11 @@
1921
<PackageVersion Include="AWSSDK.S3" Version="4.0.0.1" />
2022
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
2123
<PackageVersion Include="Elastic.Ingest.Elasticsearch" Version="0.11.3" />
24+
<PackageVersion Include="MartinCostello.Logging.XUnit.v3" Version="0.6.0" />
2225
<PackageVersion Include="Microsoft.OpenApi" Version="2.0.0-preview9" />
2326
<PackageVersion Include="System.Text.Json" Version="9.0.5" />
27+
<PackageVersion Include="TUnit" Version="0.25.21" />
28+
<PackageVersion Include="xunit.v3.extensibility.core" Version="2.0.2" />
2429
</ItemGroup>
2530
<!-- Build -->
2631
<ItemGroup>

docs-builder.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ EndProject
2525
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = ".github", ".github\.github.csproj", "{1A8659C1-222A-4824-B562-ED8F88658C05}"
2626
EndProject
2727
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{67B576EE-02FA-4F9B-94BC-3630BC09ECE5}"
28+
ProjectSection(SolutionItems) = preProject
29+
tests\Directory.Build.props = tests\Directory.Build.props
30+
EndProjectSection
2831
EndProject
2932
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Markdown.Tests", "tests\Elastic.Markdown.Tests\Elastic.Markdown.Tests.csproj", "{B27C5107-128B-465A-B8F8-8985399E4CFB}"
3033
EndProject
@@ -119,6 +122,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{6FAB56
119122
config\navigation.yml = config\navigation.yml
120123
EndProjectSection
121124
EndProject
125+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests-integration", "tests-integration", "{BCAD38D5-6C83-46E2-8398-4BE463931098}"
126+
ProjectSection(SolutionItems) = preProject
127+
tests-integration\Directory.Build.props = tests-integration\Directory.Build.props
128+
EndProjectSection
129+
EndProject
130+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests-integration\Elastic.Assembler.IntegrationTests", "tests-integration\Elastic.Assembler.IntegrationTests\Elastic.Assembler.IntegrationTests.csproj", "{A272D3EC-FAAF-4795-A796-302725382AFF}"
131+
EndProject
122132
Global
123133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
124134
Debug|Any CPU = Debug|Any CPU
@@ -204,6 +214,10 @@ Global
204214
{164F55EC-9412-4CD4-81AD-3598B57632A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
205215
{164F55EC-9412-4CD4-81AD-3598B57632A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
206216
{164F55EC-9412-4CD4-81AD-3598B57632A6}.Release|Any CPU.Build.0 = Release|Any CPU
217+
{A272D3EC-FAAF-4795-A796-302725382AFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
218+
{A272D3EC-FAAF-4795-A796-302725382AFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
219+
{A272D3EC-FAAF-4795-A796-302725382AFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
220+
{A272D3EC-FAAF-4795-A796-302725382AFF}.Release|Any CPU.Build.0 = Release|Any CPU
207221
EndGlobalSection
208222
GlobalSection(NestedProjects) = preSolution
209223
{4D198E25-C211-41DC-9E84-B15E89BD7048} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
@@ -234,5 +248,6 @@ Global
234248
{89B83007-71E6-4B57-BA78-2544BFA476DB} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
235249
{111E7029-BB29-4039-9B45-04776798A8DD} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
236250
{164F55EC-9412-4CD4-81AD-3598B57632A6} = {67B576EE-02FA-4F9B-94BC-3630BC09ECE5}
251+
{A272D3EC-FAAF-4795-A796-302725382AFF} = {BCAD38D5-6C83-46E2-8398-4BE463931098}
237252
EndGlobalSection
238253
EndGlobal
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<!-- Src Directory Build Properties -->
4+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
5+
<PropertyGroup>
6+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
7+
<UseMicrosoftTestingPlatformRunner>false</UseMicrosoftTestingPlatformRunner>
8+
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
9+
<NoWarn>CA1822</NoWarn>
10+
11+
<IsPackable>false</IsPackable>
12+
<IsTestProject>true</IsTestProject>
13+
<OutputType>Exe</OutputType>
14+
15+
</PropertyGroup>
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
18+
<PackageReference Include="xunit.v3" />
19+
<PackageReference Include="xunit.runner.visualstudio" />
20+
<PackageReference Include="GitHubActionsTestLogger" />
21+
<PackageReference Include="MartinCostello.Logging.XUnit.v3" />
22+
<PackageReference Include="xunit.v3.extensibility.core" />
23+
24+
<PackageReference Include="FluentAssertions" />
25+
<PackageReference Include="JetBrains.Annotations" />
26+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Using Include="Xunit"/>
31+
</ItemGroup>
32+
33+
</Project>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Collections.ObjectModel;
6+
using System.IO.Abstractions;
7+
using Documentation.Assembler;
8+
using Documentation.Assembler.Building;
9+
using Documentation.Assembler.Legacy;
10+
using Documentation.Assembler.Navigation;
11+
using Documentation.Assembler.Sourcing;
12+
using Documentation.Builder.Http;
13+
using Elastic.Documentation.Configuration;
14+
using Elastic.Documentation.Configuration.Assembler;
15+
using Elastic.Documentation.Configuration.Versions;
16+
using Elastic.Documentation.LegacyDocs;
17+
using Elastic.Documentation.Tooling.Diagnostics.Console;
18+
using Microsoft.Extensions.Logging;
19+
using FluentAssertions;
20+
using Xunit;
21+
22+
[assembly: CaptureConsole, AssemblyFixture(typeof(Elastic.Assembler.IntegrationTests.AssembleFixture))]
23+
24+
namespace Elastic.Assembler.IntegrationTests;
25+
26+
27+
public class AssembleFixture : IAsyncLifetime
28+
{
29+
private static IFileSystem FileSystem { get; } = new FileSystem();
30+
public ConfigurationFileProvider ConfigurationFileProvider { get; } = new(FileSystem);
31+
public StaticWebHost WebsiteHost { get; private set; } = null!;
32+
public Task WebsiteRunning { get; private set; } = null!;
33+
34+
/// <inheritdoc />
35+
public async ValueTask DisposeAsync()
36+
{
37+
GC.SuppressFinalize(this);
38+
await WebsiteHost.StopAsync(TestContext.Current.CancellationToken);
39+
}
40+
41+
/// <inheritdoc />
42+
public async ValueTask InitializeAsync()
43+
{
44+
var ctx = TestContext.Current.CancellationToken;
45+
var logFactory = LoggerFactory.Create(builder =>
46+
{
47+
_ = builder.AddConsole();
48+
});
49+
await using var collector = new ConsoleDiagnosticsCollector(logFactory, null).StartAsync(ctx);
50+
51+
var assemblyConfiguration = AssemblyConfiguration.Create(ConfigurationFileProvider);
52+
var versionsConfig = ConfigurationFileProvider.CreateVersionConfiguration();
53+
54+
var assembleContext = new AssembleContext(assemblyConfiguration, ConfigurationFileProvider, "dev", collector, FileSystem, FileSystem, null, null);
55+
var cloner = new AssemblerRepositorySourcer(logFactory, assembleContext);
56+
57+
_ = await cloner.CloneAll(false, ctx);
58+
59+
_ = GlobalNavigationFile.ValidatePathPrefixes(assembleContext);
60+
61+
var checkoutResult = cloner.GetAll();
62+
var checkouts = checkoutResult.Checkouts.ToArray();
63+
64+
if (checkouts.Length == 0)
65+
throw new Exception("No checkouts found");
66+
67+
var assembleSources = await AssembleSources.AssembleAsync(logFactory, assembleContext, checkouts, versionsConfig, ctx);
68+
var navigationFile = new GlobalNavigationFile(assembleContext, assembleSources);
69+
70+
var navigation = new GlobalNavigation(assembleSources, navigationFile);
71+
72+
var pathProvider = new GlobalNavigationPathProvider(navigationFile, assembleSources, assembleContext);
73+
var htmlWriter = new GlobalNavigationHtmlWriter(logFactory, navigation, collector);
74+
var legacyPageChecker = new LegacyPageChecker();
75+
var historyMapper = new PageLegacyUrlMapper(legacyPageChecker, assembleSources.HistoryMappings);
76+
77+
var exporters = new HashSet<ExportOption>([ExportOption.Html, ExportOption.Configuration]);
78+
var builder = new AssemblerBuilder(logFactory, assembleContext, navigation, htmlWriter, pathProvider, historyMapper);
79+
await builder.BuildAllAsync(assembleSources.AssembleSets, exporters, ctx);
80+
81+
await cloner.WriteLinkRegistrySnapshot(checkoutResult.LinkRegistrySnapshot, ctx);
82+
83+
var redirectsPath = Path.Combine(assembleContext.OutputDirectory.FullName, "redirects.json");
84+
85+
var sitemapBuilder = new SitemapBuilder(navigation.NavigationItems, assembleContext.WriteFileSystem, assembleContext.OutputDirectory);
86+
sitemapBuilder.Generate();
87+
88+
await collector.StopAsync(ctx);
89+
90+
WebsiteHost = new StaticWebHost(4001);
91+
WebsiteRunning = WebsiteHost.RunAsync(ctx);
92+
}
93+
94+
}
95+
96+
public class DatabaseTestClass1
97+
{
98+
public AssembleFixture AssembleTestContext { get; }
99+
100+
public DatabaseTestClass1(AssembleFixture fixture) => AssembleTestContext = fixture;
101+
102+
[Fact]
103+
public async Task X()
104+
{
105+
await AssembleTestContext.WebsiteRunning;
106+
AssembleTestContext.Should().NotBeNull();
107+
}
108+
109+
110+
// ...
111+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Elastic.Assembler.IntegrationTests;
6+
7+
public class Class1
8+
{
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\src\Elastic.Documentation\Elastic.Documentation.csproj" />
11+
<ProjectReference Include="..\..\src\tooling\docs-assembler\docs-assembler.csproj" />
12+
<ProjectReference Include="..\..\src\tooling\docs-builder\docs-builder.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
</ItemGroup>
17+
18+
</Project>

tests/Directory.Build.props

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<!-- Src Directory Build Properties -->
4+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>
5+
<PropertyGroup>
6+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
7+
<UseMicrosoftTestingPlatformRunner>false</UseMicrosoftTestingPlatformRunner>
8+
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
9+
<NoWarn>CA1822</NoWarn>
10+
11+
<IsPackable>false</IsPackable>
12+
<IsTestProject>true</IsTestProject>
13+
<OutputType>Exe</OutputType>
14+
15+
</PropertyGroup>
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
18+
<PackageReference Include="xunit.v3" />
19+
<PackageReference Include="xunit.runner.visualstudio" />
20+
<PackageReference Include="GitHubActionsTestLogger" />
21+
22+
<PackageReference Include="FluentAssertions" />
23+
<PackageReference Include="JetBrains.Annotations" />
24+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Using Include="Xunit"/>
29+
</ItemGroup>
30+
31+
</Project>

tests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csproj

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,10 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
8-
<IsPackable>false</IsPackable>
9-
<IsTestProject>true</IsTestProject>
10-
<OutputType>Exe</OutputType>
11-
12-
<UseMicrosoftTestingPlatformRunner>false</UseMicrosoftTestingPlatformRunner>
13-
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
14-
<NoWarn>CA1822</NoWarn>
155
</PropertyGroup>
166

17-
<ItemGroup>
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
19-
<PackageReference Include="xunit.v3" />
20-
<PackageReference Include="xunit.runner.visualstudio" />
21-
<PackageReference Include="GitHubActionsTestLogger" />
22-
23-
<PackageReference Include="FluentAssertions" />
24-
<PackageReference Include="JetBrains.Annotations" />
25-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
26-
</ItemGroup>
27-
287
<ItemGroup>
298
<ProjectReference Include="..\..\src\Elastic.ApiExplorer\Elastic.ApiExplorer.csproj"/>
309
</ItemGroup>
3110

32-
<ItemGroup>
33-
<Using Include="Xunit"/>
34-
</ItemGroup>
35-
3611
</Project>
Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
</PropertyGroup>
25

3-
4-
<PropertyGroup>
5-
<TargetFramework>net9.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
9-
<IsPackable>false</IsPackable>
10-
<IsTestProject>true</IsTestProject>
11-
<OutputType>Library</OutputType>
12-
13-
<UseMicrosoftTestingPlatformRunner>false</UseMicrosoftTestingPlatformRunner>
14-
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
15-
</PropertyGroup>
16-
17-
<ItemGroup>
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
19-
<PackageReference Include="xunit.v3" />
20-
<PackageReference Include="xunit.runner.visualstudio" />
21-
<PackageReference Include="GitHubActionsTestLogger" />
22-
<PackageReference Include="FluentAssertions" />
23-
<PackageReference Include="JetBrains.Annotations" />
24-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
25-
</ItemGroup>
26-
27-
<ItemGroup>
28-
<Using Include="Xunit"/>
29-
</ItemGroup>
30-
31-
<ItemGroup>
32-
<ProjectReference Include="..\..\src\Elastic.Documentation.LegacyDocs\Elastic.Documentation.LegacyDocs.csproj" />
33-
</ItemGroup>
6+
<ItemGroup>
7+
<ProjectReference Include="..\..\src\Elastic.Documentation.LegacyDocs\Elastic.Documentation.LegacyDocs.csproj"/>
8+
</ItemGroup>
349
</Project>

tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,16 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
8-
<IsPackable>false</IsPackable>
9-
<IsTestProject>true</IsTestProject>
10-
<OutputType>Exe</OutputType>
11-
12-
<UseMicrosoftTestingPlatformRunner>false</UseMicrosoftTestingPlatformRunner>
13-
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
145
</PropertyGroup>
156

167
<ItemGroup>
178
<PackageReference Include="DiffPlex" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
19-
<PackageReference Include="xunit.v3" />
20-
<PackageReference Include="xunit.runner.visualstudio" />
21-
<PackageReference Include="GitHubActionsTestLogger" />
229
<PackageReference Include="AngleSharp.Diffing" />
23-
24-
<PackageReference Include="FluentAssertions" />
25-
<PackageReference Include="JetBrains.Annotations" />
26-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
2710
</ItemGroup>
2811

2912
<ItemGroup>
3013
<ProjectReference Include="..\..\src\authoring\Elastic.Documentation.Refactor\Elastic.Documentation.Refactor.csproj" />
3114
<ProjectReference Include="..\..\src\Elastic.Markdown\Elastic.Markdown.csproj"/>
3215
</ItemGroup>
3316

34-
<ItemGroup>
35-
<Using Include="Xunit"/>
36-
</ItemGroup>
37-
3817
</Project>

0 commit comments

Comments
 (0)