Skip to content

Commit 28872f7

Browse files
Bugfix. Directory creation if not present.
1 parent 1e44746 commit 28872f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CICD.Tools.GitHubToCatalogYamlTests/CatalogManagerTests.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
[TestClass]
2020
public class CatalogManagerTests
2121
{
22+
private Mock<IDirectoryIO> mockDirectory;
2223
private Mock<IFileSystem> mockFileSystem;
2324
private Microsoft.Extensions.Logging.ILogger logger;
2425
private Mock<IGitHubService> mockGitHubService;
2526
private CatalogManager catalogManager;
2627
private const string workspace = "testWorkspace";
2728
private const string catalogFilePath = "testWorkspace/catalog.yml";
2829
private const string manifestFilePath = "testWorkspace/manifest.yml";
30+
private const string autoGeneratorFilePath = "testWorkspace/.githubtocatalog/auto-generated-catalog.yml";
2931

3032
[TestInitialize]
3133
public void Setup()
@@ -43,6 +45,12 @@ public void Setup()
4345

4446
mockFileSystem.Setup(fs => fs.Path.Combine(workspace, "catalog.yml")).Returns(catalogFilePath);
4547
mockFileSystem.Setup(fs => fs.Path.Combine(workspace, "manifest.yml")).Returns(manifestFilePath);
48+
mockFileSystem.Setup(fs => fs.Path.Combine(workspace, ".githubtocatalog", "auto-generated-catalog.yml")).Returns(autoGeneratorFilePath);
49+
50+
mockDirectory = new Mock<IDirectoryIO>();
51+
mockDirectory.Setup(dir => dir.CreateDirectory(It.IsAny<string>()));
52+
53+
mockFileSystem.Setup(fs => fs.Directory).Returns(mockDirectory.Object);
4654

4755
catalogManager = new CatalogManager(mockFileSystem.Object, logger, mockGitHubService.Object, workspace);
4856
}
@@ -256,10 +264,10 @@ public async Task ProcessCatalogYamlAsync_ShouldLogInformationMessage_WhenProces
256264

257265
mockFileSystem.Setup(fs => fs.Path.Combine(workspace, "catalog.yml")).Returns(catalogFilePath);
258266
mockFileSystem.Setup(fs => fs.Path.Combine(workspace, "manifest.yml")).Returns(manifestFilePath);
267+
mockFileSystem.Setup(fs => fs.Directory.CreateDirectory(It.IsAny<string>()));
259268

260269
catalogManager = new CatalogManager(mockFileSystem.Object, mockLogger.Object, mockGitHubService.Object, workspace);
261270

262-
263271
var repoName = "SLC-AS-testRepo";
264272
var yamlContent = "id: testId\ntitle: ExistingTitle\nshort_description: test description\ntags: [testTag]";
265273
mockFileSystem.Setup(fs => fs.File.Exists(catalogFilePath)).Returns(true); // catalog.yml exists

Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ private void SaveFile(CatalogYaml catalogYaml, ISerializer serializer, string ou
317317
logger.LogDebug($"Serializing and saving the updated catalog.yml file with path: {outputPath}.");
318318

319319
var updatedYaml = serializer.Serialize(catalogYaml);
320+
fs.Directory.CreateDirectory(outputPath);
320321
fs.File.WriteAllText(outputPath, updatedYaml);
321322
}
322323
}

0 commit comments

Comments
 (0)