@@ -169,6 +169,11 @@ void test_simple_put_core(const char * fileName,
169169
170170 std::string dataDir = TestSetup::getDataDir ();
171171 std::string file = dataDir + fileName;
172+ if (uploadFolder)
173+ {
174+ file += PATH_SEP;
175+ file += " **" ;
176+ }
172177 std::string putCommand = " put file://" + file + " @%test_small_put" ;
173178 if (testUnicode)
174179 {
@@ -927,34 +932,33 @@ void test_putget_subfolder_core(bool testUnicode)
927932
928933 // use get command to have local files in nested subfolder
929934 std::string cmd = " get '@%test_small_put/" + filename + " .gz' " ;
930- std::string sub1 = " sub1" ;
931- std::string sub1Platform = sub1;
932- std::string localPath1 = " file://" ;
935+ std::string sub2 = " sub2" ;
936+ std::string localPath = " file://" ;
937+
938+ localPath += dataDir + " subfoldertest" + PATH_SEP + " sub1" ;
939+ test_simple_get_data ((cmd + localPath).c_str (), " 48" , 0 , testUnicode, sf);
940+
933941 if (testUnicode)
934942 {
935- sub1 += UTF8_STR;
936- sub1Platform += PLATFORM_STR;
943+ sub2 += UTF8_STR;
937944 }
938- localPath1 += dataDir + sub1 ;
939- std::string localPath2 = localPath1 + PATH_SEP + " sub2" ;
945+ localPath += PATH_SEP ;
946+ localPath += sub2;
940947 if (testUnicode)
941948 {
942- localPath1 = " '" + localPath1 + " '" ;
943- localPath2 = " '" + localPath2 + " '" ;
944- replaceInPlace (localPath1, " \\ " , " \\\\ " );
945- replaceInPlace (localPath2, " \\ " , " \\\\ " );
949+ localPath = " '" + localPath + " '" ;
950+ replaceInPlace (localPath, " \\ " , " \\\\ " );
946951 }
947- test_simple_get_data ((cmd + localPath1).c_str (), " 48" , 0 , testUnicode, sf);
948- test_simple_get_data ((cmd + localPath2).c_str (), " 48" , 0 , testUnicode, sf);
952+ test_simple_get_data ((cmd + localPath).c_str (), " 48" , 0 , testUnicode, sf);
949953
950954 // the files returned in alphabetical order, use set to get expected files sorted
951955 std::set<std::string> expectedFiles;
952956 // put command to upload files with subfolders to stage
953- // put with createSubfolder =true so all the files in "subfolder"
954- // which would be easier to check later
955- // uploadFolder=true to skip filename checking
957+ // uploadFolder =true
958+ // createSubfolder=true as well so the uploaded files will be in path of
959+ // "subfolder" which would be easier to check later
956960 std::string basePath = " subfolder/" ;
957- test_simple_put_core (sub1. c_str () , // filename
961+ test_simple_put_core (" subfoldertest " , // filename
958962 " auto" , // source compression
959963 true , // auto compress
960964 false , // copyUploadFile
@@ -973,15 +977,17 @@ void test_putget_subfolder_core(bool testUnicode)
973977 testUnicode, // testUnicode
974978 true // uploadFolder
975979 );
976- expectedFiles.insert (basePath + sub1 + " /" + filename + " .gz" );
977- expectedFiles.insert (basePath + sub1 + " / sub2/" + filename + " .gz" );
980+ expectedFiles.insert (basePath + " sub1 /" + filename + " .gz" );
981+ expectedFiles.insert (basePath + " sub1/ " + sub2 + " /" + filename + " .gz" );
978982
979983 // get command to download uploaded files into a new folder sub3
980- cmd = " get '@%test_small_put/subfolder/" + sub1 + " ' file://" + dataDir + " sub3" ;
984+ cmd = " get @%test_small_put/subfolder file://" +
985+ dataDir + " subfoldertest" + PATH_SEP + " put2" + PATH_SEP + " sub3" ;
981986 test_simple_get_data (cmd.c_str (), " 48" , 0 , testUnicode, sf);
982987
983988 // put command to upload downloaded file again
984- test_simple_put_core (" sub3" , // filename
989+ std::string put2Path = std::string (" subfoldertest" ) + PATH_SEP + " put2" ;
990+ test_simple_put_core (put2Path.c_str (), // filename
985991 " auto" , // source compression
986992 true , // auto compress
987993 false , // copyUploadFile
@@ -1000,8 +1006,8 @@ void test_putget_subfolder_core(bool testUnicode)
10001006 testUnicode, // testUnicode
10011007 true // uploadFolder
10021008 );
1003- expectedFiles.insert (basePath + " sub3/subfolder/" + sub1 + " /" + filename + " .gz" );
1004- expectedFiles.insert (basePath + " sub3/subfolder/" + sub1 + " /sub2 /" + filename + " .gz" );
1009+ expectedFiles.insert (basePath + " sub3/subfolder/sub1/" + filename + " .gz" );
1010+ expectedFiles.insert (basePath + " sub3/subfolder/sub1/ " + sub2 + " /" + filename + " .gz" );
10051011
10061012 // run list command to check result
10071013 SF_STMT *sfstmt = NULL ;
@@ -1029,8 +1035,7 @@ void test_putget_subfolder_core(bool testUnicode)
10291035
10301036 snowflake_stmt_term (sfstmt);
10311037 snowflake_term (sf);
1032- remove_all (dataDir + sub1Platform);
1033- remove_all (dataDir + " sub3" );
1038+ remove_all (dataDir + " subfoldertest" );
10341039}
10351040
10361041void test_putget_subfolder (void **unused)
@@ -1834,6 +1839,8 @@ int main(void) {
18341839 }
18351840
18361841 const struct CMUnitTest tests[] = {
1842+ cmocka_unit_test_teardown (test_putget_subfolder, teardown),
1843+ cmocka_unit_test_teardown (test_putget_subfolder_with_unicode, teardown),
18371844 cmocka_unit_test_teardown (test_simple_put_auto_compress, teardown),
18381845 cmocka_unit_test_teardown (test_simple_put_config_temp_dir, teardown),
18391846 cmocka_unit_test_teardown (test_simple_put_auto_detect_gzip, teardown),
@@ -1865,8 +1872,6 @@ int main(void) {
18651872 cmocka_unit_test_teardown (test_simple_put_with_noproxy_fromenv, teardown),
18661873 cmocka_unit_test_teardown (test_upload_file_to_stage_using_stream, donothing),
18671874 cmocka_unit_test_teardown (test_put_get_with_unicode, teardown),
1868- cmocka_unit_test_teardown (test_putget_subfolder_with_unicode, teardown),
1869- cmocka_unit_test_teardown (test_putget_subfolder, teardown),
18701875 };
18711876 int ret = cmocka_run_group_tests (tests, gr_setup, gr_teardown);
18721877 return ret;
0 commit comments