Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Avoid throwing an exception when a directory does not contain SQL files #92

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Loader/YeSqlLoader.HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ private Result<IEnumerable<SqlFile>> LoadFromDirectory(string directoryName)
}

var sqlFiles = GetSqlFiles(path);
if (sqlFiles.IsEmpty())
{
_validationResult.Add(string.Format(ExceptionMessages.NoneFileFoundInSpecifiedDirectory, directoryName));
return Result<IEnumerable<SqlFile>>.Failure();
}

return Result<IEnumerable<SqlFile>>.Success(sqlFiles);
}

Expand Down
1 change: 0 additions & 1 deletion src/Models/ExceptionMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ internal class ExceptionMessages
public const string FileHasNotSqlExtension = "error: '{0}' has no sql extension.";
public const string CollectionHasNullValueOrOnlyWhitespace = "'{0}' collection cannot contain elements with a null value, " +
"an empty string or consists only of white-space characters.";
public const string NoneFileFoundInSpecifiedDirectory = "error: No sql file found in the directory '{0}'.";
public const string YeSqlParserDefault = "error: Parser found syntax errors.";
public const string YeSqlLoaderDefault = "error: Loader found an error while loading the SQL file.";
public const string DataSourceIsEmptyOrWhitespace = "Data source is empty or consists only in whitespace.";
Expand Down
13 changes: 4 additions & 9 deletions tests/Loader/YeSqlLoaderTests.Directories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public void LoadFromDirectories_WhenErrorsAreFound_ShouldThrowAggregateException
};
var loaderErrors = new[]
{
string.Format(ExceptionMessages.DirectoryNotFound, "directory_not_found"),
string.Format(ExceptionMessages.NoneFileFoundInSpecifiedDirectory, "env")
string.Format(ExceptionMessages.DirectoryNotFound, "directory_not_found")
};
var parserErrors = new[]
{
Expand Down Expand Up @@ -80,21 +79,17 @@ public void LoadFromDirectories_WhenCollectionHasNullValueOrOnlyWhitespace_Shoul
}

[Test]
public void LoadFromDirectories_WhenNotExistsSqlFilesInDirectory_ShouldThrowAggregateException()
public void LoadFromDirectories_WhenNotExistsSqlFilesInDirectory_ShouldNotThrowException()
{
// Arrange
var loader = new YeSqlLoader();
var directory = "env";
var expectedMessage = string.Format(ExceptionMessages.NoneFileFoundInSpecifiedDirectory, directory);

// Act
Action action = () => loader.LoadFromDirectories(directory);
var sqlStatements = loader.LoadFromDirectories(directory);

// Assert
action.Should()
.Throw<AggregateException>()
.WithInnerException<YeSqlLoaderException>()
.WithMessage(expectedMessage);
sqlStatements.Should().BeEmpty();
}

[Test]
Expand Down