forked from asyncapi/saunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asyncapi#197 Produce AsyncAPI documents at build time - test + setup …
…with local nuget source
- Loading branch information
Senn Geerts
authored and
Senn Geerts
committed
Jul 7, 2024
1 parent
88c5caf
commit a2813e2
Showing
16 changed files
with
367 additions
and
165 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<!-- Adds the folder "local-nuget-source" in root of the project as a nuget source. | ||
Projects that build a nuget package publish in this folder so dependent projects can use the local build packages --> | ||
<add key="Local-sauter" value="local-nuget-source" /> | ||
|
||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||
</packageSources> | ||
</configuration> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
28 changes: 28 additions & 0 deletions
28
test/AsyncAPI.Saunter.Generator.Build.Tests/AsyncAPI.Saunter.Generator.Build.Tests.csproj
This file contains 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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
<PackageReference Include="Shouldly" Version="4.2.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\examples\StreetlightsAPI\StreetlightsAPI.csproj" /> | ||
<ProjectReference Include="..\AsyncAPI.Saunter.Generator.Cli.Tests\AsyncAPI.Saunter.Generator.Cli.Tests.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
74 changes: 74 additions & 0 deletions
74
test/AsyncAPI.Saunter.Generator.Build.Tests/StreetlightsApiBuildTests.cs
This file contains 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,74 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Diagnostics; | ||
using AsyncAPI.Saunter.Generator.Cli.Tests; | ||
using Shouldly; | ||
using Xunit.Abstractions; | ||
|
||
namespace AsyncAPI.Saunter.Generator.Build.Tests; | ||
|
||
public class StreetlightsApiBuildTests(ITestOutputHelper output) | ||
{ | ||
private string Run(string file, string args, string workingDirectory, int expectedExitCode = 0) | ||
{ | ||
var process = Process.Start(new ProcessStartInfo(file) | ||
{ | ||
Arguments = args, | ||
WorkingDirectory = workingDirectory, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false, | ||
}); | ||
process.WaitForExit(TimeSpan.FromSeconds(20)); | ||
var stdOut = process.StandardOutput.ReadToEnd().Trim(); | ||
var stdError = process.StandardError.ReadToEnd().Trim(); | ||
output.WriteLine($"### Output of \"{file} {args}\""); | ||
output.WriteLine(stdOut); | ||
output.WriteLine(stdError); | ||
|
||
process.ExitCode.ShouldBe(expectedExitCode); | ||
return stdOut; | ||
} | ||
|
||
private const string csprojPath = "../../../../../examples/StreetlightsAPI/StreetlightsAPI.csproj"; | ||
|
||
[Fact] | ||
public void BuildingCsprojGeneratesSpecFilesTest() | ||
{ | ||
var pwd = Directory.GetCurrentDirectory(); | ||
var csproj = Path.GetFullPath(Path.Combine(pwd, csprojPath)); | ||
output.WriteLine($"Current working directory: {pwd}"); | ||
output.WriteLine($"Csproj under test: {csproj}"); | ||
File.Exists(csproj).ShouldBeTrue(); | ||
|
||
var csprojDir = Path.GetDirectoryName(csproj); | ||
var specDir = Path.Combine(csprojDir, "specs"); | ||
|
||
// Spec files should have been generated during the builds of the solution | ||
Directory.GetFiles(specDir).Length.ShouldBe(2, $"#Spec files initial, path: {specDir}"); | ||
File.ReadAllText(Path.Combine(specDir, "streetlights.yml")).ShouldBe(ExpectedSpecFiles.Yml_v2_6, "yml"); | ||
File.ReadAllText(Path.Combine(specDir, "streetlights.json")).ShouldBe(ExpectedSpecFiles.Json_v2_6, "json"); | ||
|
||
// Delete spec files | ||
foreach (var file in Directory.EnumerateFiles(specDir)) | ||
{ | ||
File.Delete(file); | ||
} | ||
Directory.GetFiles(specDir).Length.ShouldBe(0, $"#Spec files after deleting them all, path: {specDir}"); | ||
|
||
// Run build | ||
var stdOut = this.Run("dotnet", "build", csprojDir); | ||
stdOut.ShouldContain($"AsyncAPI json successfully written to {Path.Combine(specDir, "streetlights.json")}"); | ||
stdOut.ShouldContain($"AsyncAPI yml successfully written to {Path.Combine(specDir, "streetlights.yml")}"); | ||
stdOut.ShouldContain("Build succeeded."); | ||
stdOut.ShouldContain("0 Warning(s)"); | ||
stdOut.ShouldContain("0 Error(s)"); | ||
|
||
// Check that spec files are actually re-generated | ||
Directory.GetFiles(specDir).Length.ShouldBe(2, $"#Spec files after running build, path: {specDir}"); | ||
File.ReadAllText(Path.Combine(specDir, "streetlights.yml")).ShouldBe(ExpectedSpecFiles.Yml_v2_6, "yml"); | ||
File.ReadAllText(Path.Combine(specDir, "streetlights.json")).ShouldBe(ExpectedSpecFiles.Json_v2_6, "json"); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.