Skip to content

Commit

Permalink
SNOW-950923 codecov fixes, review suggestions to provide more checks …
Browse files Browse the repository at this point in the history
…in tests
  • Loading branch information
sfc-gh-mhofman committed Jan 17, 2024
1 parent e280fba commit dbbb98a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
26 changes: 26 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Data.Common;
using System.IO.Compression;
using System.Text;
using Castle.Components.DictionaryAdapter;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.IntegrationTests
{
Expand Down Expand Up @@ -227,6 +229,30 @@ public void TestPutFileProvidesQueryIdOnFailure()
// Assert
Assert.IsNotEmpty(queryId);
Assert.DoesNotThrow(()=>Guid.Parse(queryId));
SnowflakeDbExceptionAssert.HasErrorCode(snowflakeDbException, SFError.IO_ERROR_ON_GETPUT_COMMAND);
}
}

[Test]
public void TestPutFileWithSyntaxErrorProvidesQueryIdOnFailure()
{
// Arrange
// Set the PUT query variables but do not create a file
t_inputFilePath = "unexisting_file.csv SOME CODE FORCING SYNTAX ERROR";
t_internalStagePath = $"@{t_schemaName}.{t_stageName}";

// Act
using (var conn = new SnowflakeDbConnection(ConnectionString))
{
conn.Open();
var snowflakeDbException = Assert.Throws<SnowflakeDbException>(()=>PutFile(conn));
var queryId = snowflakeDbException.QueryId;

// Assert
Assert.IsNotEmpty(queryId);
Assert.DoesNotThrow(()=>Guid.Parse(queryId));
Assert.That(snowflakeDbException.ErrorCode, Is.EqualTo(1003));
Assert.That(snowflakeDbException.InnerException, Is.Null);
}
}

Expand Down
8 changes: 6 additions & 2 deletions Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Amazon.S3.Transfer;
using Snowflake.Data.Client;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.UnitTests
{
Expand Down Expand Up @@ -311,7 +312,7 @@ public void TestUploadWithGZIPCompression()
}

[Test]
public void TestUploadWithWilcardInTheFilename()
public void TestUploadWithWildcardInTheFilename()
{
// Arrange
UploadSetUpFile();
Expand Down Expand Up @@ -461,7 +462,7 @@ public void TestUploadWithWildcardInTheDirectoryPath()
}

[Test]
public void TestUploadThrowsArgumentExceptionForMissingRootDirectoryWithWildcard()
public void TestUploadThrowsExceptionForMissingRootDirectoryWithWildcard()
{
// Arrange
UploadSetUpFile();
Expand Down Expand Up @@ -501,6 +502,7 @@ public void TestUploadThrowsArgumentExceptionForMissingRootDirectoryWithWildcard

// Assert
Assert.AreEqual(_responseData.queryId, ex.QueryId);
SnowflakeDbExceptionAssert.HasErrorCode(ex, SFError.IO_ERROR_ON_GETPUT_COMMAND);
Assert.That(ex.Message, Does.Match($"No file found for: {tempUploadRootDirectory}\\*/{tempUploadSecondDirectory}\\*/{mockFileName}"));

for (int i = 0; i < numberOfDirectories; i++)
Expand Down Expand Up @@ -595,6 +597,7 @@ public void TestDownloadThrowsErrorFileNotFound()

// Assert
Assert.AreEqual(_responseData.queryId, ex.QueryId);
SnowflakeDbExceptionAssert.HasErrorCode(ex, SFError.IO_ERROR_ON_GETPUT_COMMAND);
Assert.IsInstanceOf<AggregateException>(ex.InnerException);
var innerException = ((AggregateException)ex.InnerException)?.InnerExceptions[0];
Assert.IsInstanceOf<FileNotFoundException>(innerException);
Expand Down Expand Up @@ -626,6 +629,7 @@ public void TestDownloadThrowsErrorDirectoryNotFound()

// Assert
Assert.AreEqual(_responseData.queryId, ex.QueryId);
SnowflakeDbExceptionAssert.HasErrorCode(ex, SFError.IO_ERROR_ON_GETPUT_COMMAND);
Assert.IsInstanceOf<AggregateException>(ex.InnerException);
var innerException = ((AggregateException)ex.InnerException)?.InnerExceptions[0];
Assert.IsInstanceOf<DirectoryNotFoundException>(innerException);
Expand Down
14 changes: 14 additions & 0 deletions Snowflake.Data.Tests/Util/SnowflakeDbExceptionAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Snowflake.Data.Core;
using Snowflake.Data.Client;
using NUnit.Framework;

namespace Snowflake.Data.Tests.Util
{
public static class SnowflakeDbExceptionAssert
{
public static void HasErrorCode(SnowflakeDbException exception, SFError sfError)
{
Assert.AreEqual(exception.ErrorCode, sfError.GetAttribute<SFErrorAttr>().errorCode);
}
}
}
2 changes: 1 addition & 1 deletion Snowflake.Data/Client/SnowflakeDbException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class SnowflakeDbException : DbException
static private ResourceManager rm = new ResourceManager("Snowflake.Data.Core.ErrorMessages",
typeof(SnowflakeDbException).Assembly);

public new string SqlState { get; private set; }
public string SqlState { get; private set; }

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, GCP)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AZURE)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AWS)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, GCP)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AZURE)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AWS)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AZURE)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, GCP)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 26 in Snowflake.Data/Client/SnowflakeDbException.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AWS)

'SnowflakeDbException.SqlState' hides inherited member 'DbException.SqlState'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

private int VendorCode;

Expand Down
1 change: 0 additions & 1 deletion Snowflake.Data/Core/FileTransfer/SFFileTransferAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public void execute()
}
throw new SnowflakeDbException(SFError.IO_ERROR_ON_GETPUT_COMMAND, TransferMetadata.queryId, e);
}

}

public async Task executeAsync(CancellationToken cancellationToken)
Expand Down
3 changes: 1 addition & 2 deletions Snowflake.Data/Core/SFStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,8 @@ internal SFBaseResultSet Execute(int timeout, string sql, Dictionary<string, Bin
catch (Exception ex)
{
logger.Error("Query execution failed.", ex);
if (ex is SnowflakeDbException)
if (ex is SnowflakeDbException snowflakeDbException)
{
var snowflakeDbException = (SnowflakeDbException)ex;
this._lastQueryId = snowflakeDbException.QueryId;
}
throw;
Expand Down

0 comments on commit dbbb98a

Please sign in to comment.