Skip to content

Commit

Permalink
asyncapi#196 permission issue?
Browse files Browse the repository at this point in the history
  • Loading branch information
Senn Geerts authored and Senn Geerts committed Jul 13, 2024
1 parent 4f1064e commit 74260a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
16 changes: 1 addition & 15 deletions src/AsyncAPI.Saunter.Generator.Cli/ToFile/StreamProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,7 @@ public Stream GetStreamFor(string path)

if (!string.IsNullOrEmpty(path))
{
var directory = new DirectoryInfo(Path.GetDirectoryName(path));
var sw = Stopwatch.StartNew();
do
{
try
{
directory.Create();
}
catch (Exception e) when (sw.Elapsed < TimeSpan.FromMilliseconds(250))
{
logger.LogDebug(e, $"Retry... {directory.Parent.Exists}, {directory.Parent.Parent.Exists}, {directory.Parent.Parent.Parent.Exists}");
Thread.Sleep(100);
}
}
while (!directory.Exists);
Directory.CreateDirectory(Path.GetDirectoryName(path));
}

return path != null ? File.Create(path) : Console.OpenStandardOutput();
Expand Down
22 changes: 11 additions & 11 deletions test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ Retrieves AsyncAPI spec from a startup assembly and writes to file.
[InlineData("StreetlightsAPI.TopLevelStatement", "net8.0")]
public void Streetlights_ExportSpecTest(string csprojName, string targetFramework)
{
var path = Path.Combine(Directory.GetCurrentDirectory(), csprojName, "specs");
var path = Path.Combine(Directory.GetCurrentDirectory());
output.WriteLine($"Output path: {path}");
var stdOut = RunTool($"tofile ../../../../../examples/{csprojName}/bin/Debug/{targetFramework}/{csprojName}.dll --output {path} --format json,yml,yaml");
var stdOut = RunTool($"tofile ../../../../../examples/{csprojName}/bin/Debug/{targetFramework}/{csprojName}.dll --output {path} --filename {csprojName}.{{extension}} --format json,yml,yaml");

stdOut.ShouldNotBeEmpty();
stdOut.ShouldContain($"AsyncAPI yaml successfully written to {Path.Combine(path, "asyncapi.yaml")}");
stdOut.ShouldContain($"AsyncAPI yml successfully written to {Path.Combine(path, "asyncapi.yml")}");
stdOut.ShouldContain($"AsyncAPI json successfully written to {Path.Combine(path, "asyncapi.json")}");
stdOut.ShouldContain($"AsyncAPI yaml successfully written to {Path.Combine(path, $"{csprojName}.yaml")}");
stdOut.ShouldContain($"AsyncAPI yml successfully written to {Path.Combine(path, $"{csprojName}.yml")}");
stdOut.ShouldContain($"AsyncAPI json successfully written to {Path.Combine(path, $"{csprojName}.json")}");

File.Exists(Path.Combine(path, "asyncapi.yml")).ShouldBeTrue("asyncapi.yml");
File.Exists(Path.Combine(path, "asyncapi.yaml")).ShouldBeTrue("asyncapi.yaml");
File.Exists(Path.Combine(path, "asyncapi.json")).ShouldBeTrue("asyncapi.json");
File.Exists(Path.Combine(path, $"{csprojName}.yml")).ShouldBeTrue();
File.Exists(Path.Combine(path, $"{csprojName}.yaml")).ShouldBeTrue();
File.Exists(Path.Combine(path, $"{csprojName}.json")).ShouldBeTrue();

var yml = File.ReadAllText(Path.Combine(path, "asyncapi.yml"));
var yml = File.ReadAllText(Path.Combine(path, $"{csprojName}.yml"));
yml.ShouldBe(ExpectedSpecFiles.Yml_v2_6, "yml");

var yaml = File.ReadAllText(Path.Combine(path, "asyncapi.yaml"));
var yaml = File.ReadAllText(Path.Combine(path, $"{csprojName}.yaml"));
yaml.ShouldBe(yml, "yaml");

var json = File.ReadAllText(Path.Combine(path, "asyncapi.json"));
var json = File.ReadAllText(Path.Combine(path, $"{csprojName}.json"));
json.ShouldBe(ExpectedSpecFiles.Json_v2_6, "json");
}
}

0 comments on commit 74260a8

Please sign in to comment.