From 0f6bd288f98a3a5f4498ed5d274fd8692982b375 Mon Sep 17 00:00:00 2001 From: Louie Farol Date: Tue, 3 Dec 2024 10:10:51 -0800 Subject: [PATCH] Move test to another file --- .../FileUploadDownloadLargeFilesIT.cs | 53 ++----------------- .../IntegrationTests/SFPutGetTest.cs | 49 ++++++++++++++--- 2 files changed, 47 insertions(+), 55 deletions(-) diff --git a/Snowflake.Data.Tests/IntegrationTests/FileUploadDownloadLargeFilesIT.cs b/Snowflake.Data.Tests/IntegrationTests/FileUploadDownloadLargeFilesIT.cs index 53ec880ef..4fe42ed92 100644 --- a/Snowflake.Data.Tests/IntegrationTests/FileUploadDownloadLargeFilesIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/FileUploadDownloadLargeFilesIT.cs @@ -13,21 +13,15 @@ namespace Snowflake.Data.Tests { [TestFixture] - [NonParallelizable] public class FileUploadDownloadLargeFilesIT : SFBaseTest { private const string FileName = "large_file_to_test_dotnet_driver.json"; private static readonly string s_uniqueId = TestDataGenarator.NextAlphaNumeric(6); private static readonly string s_localFolderName = Path.Combine(Path.GetTempPath(), s_uniqueId); - private static readonly string s_localFolderWithSpaceName = Path.Combine(Path.GetTempPath() + s_uniqueId, "folder with space"); private static readonly string s_remoteFolderName = $"files_to_test_put_get_{s_uniqueId}"; - private static readonly string s_remoteFolderWithSpaceName = $"files_to_test_put_get_for_folder_with_space{s_uniqueId}"; private static readonly string s_downloadFolderName = Path.Combine(s_localFolderName, "download"); - private static readonly string s_downloadFolderWithSpaceName = Path.Combine(s_localFolderName, "download with space"); private static readonly string s_fullFileName = Path.Combine(s_localFolderName, FileName); - private static readonly string s_fullFileWithSpaceName = Path.Combine(s_localFolderWithSpaceName, FileName); private static readonly string s_fullDownloadedFileName = Path.Combine(s_downloadFolderName, FileName); - private static readonly string s_fullDownloadedFileWithSpaceName = Path.Combine(s_downloadFolderWithSpaceName, FileName); private static readonly MD5 s_md5 = MD5.Create(); [OneTimeSetUp] @@ -35,8 +29,6 @@ public static void GenerateLargeFileForTests() { CreateLocalDirectory(s_localFolderName); GenerateLargeFile(s_fullFileName); - CreateLocalDirectory(s_localFolderWithSpaceName); - GenerateLargeFile(s_fullFileWithSpaceName); } [OneTimeTearDown] @@ -44,8 +36,6 @@ public static void DeleteGeneratedLargeFile() { RemoveLocalFile(s_fullFileName); RemoveDirectory(s_localFolderName); - RemoveLocalFile(s_fullFileWithSpaceName); - RemoveDirectory(s_localFolderWithSpaceName); } [Test] @@ -65,51 +55,25 @@ public void TestThatUploadsAndDownloadsTheSameFile() RemoveLocalFile(s_fullDownloadedFileName); } - [Test] - public void TestThatUploadsAndDownloadsFilePathWithSpacesAndSingleQuotes() - { - // act - UploadFile(s_fullFileWithSpaceName, s_remoteFolderWithSpaceName, true); - DownloadFile(s_remoteFolderWithSpaceName, s_downloadFolderWithSpaceName, FileName, true); - - // assert - Assert.AreEqual( - CalcualteMD5(s_fullFileWithSpaceName), - CalcualteMD5(s_fullDownloadedFileWithSpaceName)); - - // cleanup - RemoveFilesFromServer(s_remoteFolderWithSpaceName); - RemoveLocalFile(s_fullDownloadedFileWithSpaceName); - } - private static void GenerateLargeFile(string fullFileName) { File.Delete(fullFileName); RandomJsonGenerator.GenerateRandomJsonFile(fullFileName, 128 * 1024); } - private void UploadFile(string fullFileName, string remoteFolderName, bool encloseFilePathInSingleQuotes = false) + private void UploadFile(string fullFileName, string remoteFolderName) { using (var conn = new SnowflakeDbConnection()) { conn.ConnectionString = ConnectionString + "FILE_TRANSFER_MEMORY_THRESHOLD=1048576;"; conn.Open(); var command = conn.CreateCommand(); - if (encloseFilePathInSingleQuotes) - { - // Enclosing the file path in single quotes require forward slash - fullFileName = fullFileName.Replace("\\", "/"); - command.CommandText = $"PUT 'file://{fullFileName}' @~/{remoteFolderName} AUTO_COMPRESS=FALSE"; - } - else - { - command.CommandText = $"PUT file://{fullFileName} @~/{remoteFolderName} AUTO_COMPRESS=FALSE"; - } + command.CommandText = $"PUT file://{fullFileName} @~/{remoteFolderName} AUTO_COMPRESS=FALSE"; command.ExecuteNonQuery(); } } - private void DownloadFile(string remoteFolderName, string downloadFolderName, string fileName, bool encloseFilePathInSingleQuotes = false) + private void DownloadFile(string remoteFolderName, string downloadFolderName, string fileName) { var filePattern = $"{remoteFolderName}/{fileName}"; using (var conn = new SnowflakeDbConnection()) @@ -117,16 +81,7 @@ private void DownloadFile(string remoteFolderName, string downloadFolderName, st conn.ConnectionString = ConnectionString; conn.Open(); var command = conn.CreateCommand(); - if (encloseFilePathInSingleQuotes) - { - // Enclosing the file path in single quotes require forward slash - downloadFolderName = downloadFolderName.Replace("\\", "/"); - command.CommandText = $"GET @~/{remoteFolderName} 'file://{downloadFolderName}' PATTERN='{filePattern}'"; - } - else - { - command.CommandText = $"GET @~/{remoteFolderName} file://{downloadFolderName} PATTERN='{filePattern}'"; - } + command.CommandText = $"GET @~/{remoteFolderName} file://{downloadFolderName} PATTERN='{filePattern}'"; command.ExecuteNonQuery(); } } diff --git a/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs b/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs index 2ef0c7ef9..8be31aa0c 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. */ @@ -560,6 +560,29 @@ public void TestPutGetGcsDownscopedCredential( } } + [Test] + public void TestPutFileWithSpaceAndSingleQuote() + { + var absolutePathPrefix = Path.Combine($"{Path.GetTempPath()}{Guid.NewGuid()} file path with space"); + var files = new List { + $"{absolutePathPrefix}_one.csv", + $"{absolutePathPrefix}_two.csv", + $"{absolutePathPrefix}_three.csv" + }; + PrepareFileData(files); + + // Set the PUT query variables + t_inputFilePath = $"{absolutePathPrefix}*"; + t_internalStagePath = $"@{t_schemaName}.{t_stageName}"; + + using (var conn = new SnowflakeDbConnection(ConnectionString)) + { + conn.Open(); + PutFile(conn, "", ResultStatus.UPLOADED, true); + VerifyFilesAreUploaded(conn, files, t_internalStagePath); + } + } + private void PrepareTest(string sourceFileCompressionType, StageType stageType, string stagePath, bool autoCompress, bool clientEncryption = true) { @@ -610,16 +633,30 @@ private static bool IsCompressedByTheDriver() string PutFile( SnowflakeDbConnection conn, String additionalAttribute = "", - ResultStatus expectedStatus = ResultStatus.UPLOADED) + ResultStatus expectedStatus = ResultStatus.UPLOADED, + bool encloseInSingleQuotes = false) { string queryId; using (var command = conn.CreateCommand()) { // Prepare PUT query - string putQuery = - $"PUT file://{t_inputFilePath} {t_internalStagePath}" + - $" AUTO_COMPRESS={(t_autoCompress ? "TRUE" : "FALSE")}" + - $" {additionalAttribute}"; + string putQuery; + if (encloseInSingleQuotes) + { + // Enclosing the file path in single quotes require forward slash + t_inputFilePath = t_inputFilePath.Replace("\\", "/"); + putQuery = + $"PUT 'file://{t_inputFilePath}' {t_internalStagePath}" + + $" AUTO_COMPRESS={(t_autoCompress ? "TRUE" : "FALSE")}"; + } + else + { + putQuery = + $"PUT file://{t_inputFilePath} {t_internalStagePath}" + + $" AUTO_COMPRESS={(t_autoCompress ? "TRUE" : "FALSE")}" + + $" {additionalAttribute}"; + } + // Upload file command.CommandText = putQuery; var reader = command.ExecuteReader();