Skip to content

Commit

Permalink
test: Added Cli integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 15, 2024
1 parent 5e50332 commit 15675bf
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
7 changes: 7 additions & 0 deletions OpenApiGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "specs", "specs", "{7E829AE4
specs\twitch.json = specs\twitch.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiGenerator.IntegrationTests.Cli", "src\tests\OpenApiGenerator.IntegrationTests.Cli\OpenApiGenerator.IntegrationTests.Cli.csproj", "{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -124,6 +126,10 @@ Global
{7C8C2EF1-2E1E-4623-92B6-95BDDBE4A32E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C8C2EF1-2E1E-4623-92B6-95BDDBE4A32E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C8C2EF1-2E1E-4623-92B6-95BDDBE4A32E}.Release|Any CPU.Build.0 = Release|Any CPU
{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -144,6 +150,7 @@ Global
{01D74ED6-33E1-456C-AD74-C7F5BE90D042} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
{7C8C2EF1-2E1E-4623-92B6-95BDDBE4A32E} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
{7E829AE4-1ACD-43C0-87ED-9902566DF437} = {94FE90BF-FA05-46C6-A207-6E454A236659}
{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1493AEE4-9211-46E9-BFE6-8F629EAC5693}
Expand Down
68 changes: 68 additions & 0 deletions src/tests/OpenApiGenerator.IntegrationTests.Cli/CliTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using CliWrap.Buffered;

namespace OpenApiGenerator.IntegrationTests;

[TestClass]
public class CliTests
{
[DataTestMethod]
//[DataRow("github.yaml")]
[DataRow("ipinfo.yaml")]
[DataRow("langsmith.yaml")]
//[DataRow("langsmith.json")]
[DataRow("ollama.yaml")]
[DataRow("openai.yaml")]
[DataRow("petstore.yaml")]
[DataRow("replicate.json")]
//[DataRow("special-cases.yaml")]
[DataRow("twitch.json")]
public async Task Run(string spec)
{
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
try
{
Directory.CreateDirectory(tempDirectory);

var currentDirectory = Directory.GetCurrentDirectory();
var repositoryDirectory = Path.GetFullPath(Path.Combine(currentDirectory, "../../../../../.."));
_ = await CliWrap.Cli.Wrap("dotnet")
.WithArguments([
"run",
"--project", "src/libs/OpenApiGenerator.Cli",
"generate", $"specs/{spec}",
"--output", tempDirectory,
"--namespace", "Oag",
// --json-serializer-type SystemTextJson --target-framework netstandard2.0 --generate-sdk
])
.WithWorkingDirectory(repositoryDirectory)
.ExecuteBufferedAsync();

Directory.EnumerateFiles(tempDirectory, "*", SearchOption.AllDirectories)
.Should()
.NotBeEmpty();

await File.WriteAllTextAsync(Path.Combine(tempDirectory, "Oag.csproj"), @"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Label=""Analyzers"">
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>All</AnalysisMode>
</PropertyGroup>
</Project>");

var response = await DotnetCliWrapper.Dotnet.BuildAsync(tempDirectory + "/");
Console.WriteLine(response.StandardOutput);
Console.WriteLine(response.StandardError);
response.Diagnostics.Should().BeEmpty();
}
finally
{
Directory.Delete(tempDirectory, recursive: true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="Base packages">
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="DotnetCliWrapper" Version="0.1.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>

<ItemGroup Label="GlobalUsings">
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
<Using Include="FluentAssertions" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="H.Resources.Generator" Version="1.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.14" />
<PackageReference Include="SharpYaml" Version="2.1.1" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\OpenApiGenerator.Cli\OpenApiGenerator.Cli.csproj" />
</ItemGroup>

</Project>

0 comments on commit 15675bf

Please sign in to comment.