Skip to content

Commit

Permalink
test: add unit test for SopsConfigLoader to verify exception on missi…
Browse files Browse the repository at this point in the history
…ng .sops.yaml file (#663)

Signed-off-by: Nikolai Emil Damm <[email protected]>
  • Loading branch information
devantler authored Feb 23, 2025
1 parent b554223 commit bf52aef
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/KSail.Tests/Utils/SopsConfigLoaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using KSail.Utils;

namespace KSail.Tests.Utils;

/// <summary>
/// Tests for <see cref="SopsConfigLoader"/>.
/// </summary>
public class SopsConfigLoaderTest
{
/// <summary>
/// Test that <see cref="SopsConfigLoader.LoadAsync"/> throws <see cref="KSailException"/> when no '.sops.yaml' file is found.
/// </summary>
/// <returns></returns>
[Fact]
public async Task LoadAsync_NoSopsYamlFile_ThrowsKSailException()
{
// Arrange
string testDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
_ = Directory.CreateDirectory(testDirectory);

try
{
// Act & Assert
var exception = await Assert.ThrowsAsync<KSailException>(() => SopsConfigLoader.LoadAsync(testDirectory));
Assert.Equal("'.sops.yaml' file not found in the current or parent directories", exception.Message);
}
finally
{
// Cleanup
Directory.Delete(testDirectory, true);
}
}
}

0 comments on commit bf52aef

Please sign in to comment.