test/unittests/uploader.cpp
/*
 * Two uploads. The second appends the first, but fails with an exception (because of wrong encoding).
 * In the end the file from first upload should exist but the files from second upload should be deleted.
 */
Two uploads. The second appends the first, but fails with an exception (because of wrong encoding).
In the end the file from first upload should exist but the files from second upload should be deleted.
Two uploads . The second appends the first but fails with an exception ( because of wrong encoding ) . In the end the file from first upload should exist but the files from second upload should be deleted .
TEST_F(UploaderTest, upload_failed) {
    {
        std::stringstream fake_in;
        fake_in << two_file_request_p1;
        fake_in << sessiontoken;
        fake_in << single_file_p2;
        std::stringstream fake_out;
        UploadService service(fake_in.rdbuf(), fake_out.rdbuf(), std::cerr.rdbuf());
        service.run();
    }
    {
        std::stringstream fake_in;
        fake_in << two_file_request_append_upload_p1;
        fake_in << sessiontoken;
        fake_in << two_file_request_crash_p2;
        std::stringstream fake_out;
        UploadService service(fake_in.rdbuf(), fake_out.rdbuf(), std::cerr.rdbuf());
        service.run();
        std::string line;
        std::getline(fake_out, line);
        EXPECT_EQ("Status: 500 Internal Server Error\r", line);
    }
    boost::filesystem::path base_path(temp_dir_name);
    base_path /= userID;
    base_path /= "test_upload";
    boost::filesystem::path csv_path = base_path;
    csv_path /= "hello.csv";
    boost::filesystem::path csvt_path = base_path;
    csvt_path /= "hello.csvt";
    boost::filesystem::path survive_path = base_path;
    survive_path /= "iwillsurvi.ve";
    EXPECT_FALSE(boost::filesystem::exists(csv_path));
    EXPECT_FALSE(boost::filesystem::exists(csvt_path));
    EXPECT_TRUE (boost::filesystem::exists(survive_path));
}
TEST_F ( UploaderTest , upload_failed ) { { std :: stringstream fake_in ; fake_in << two_file_request_p1 ; fake_in << sessiontoken ; fake_in << single_file_p2 ; std :: stringstream fake_out ; UploadService service ( fake_in . rdbuf ( ) , fake_out . rdbuf ( ) , std :: cerr . rdbuf ( ) ) ; service . run ( ) ; } { std :: stringstream fake_in ; fake_in << two_file_request_append_upload_p1 ; fake_in << sessiontoken ; fake_in << two_file_request_crash_p2 ; std :: stringstream fake_out ; UploadService service ( fake_in . rdbuf ( ) , fake_out . rdbuf ( ) , std :: cerr . rdbuf ( ) ) ; service . run ( ) ; std :: string line ; std :: getline ( fake_out , line ) ; EXPECT_EQ ( " \r " , line ) ; } boost :: filesystem :: path base_path ( temp_dir_name ) ; base_path /= userID ; base_path /= " " ; boost :: filesystem :: path csv_path = base_path ; csv_path /= " " ; boost :: filesystem :: path csvt_path = base_path ; csvt_path /= " " ; boost :: filesystem :: path survive_path = base_path ; survive_path /= " " ; EXPECT_FALSE ( boost :: filesystem :: exists ( csv_path ) ) ; EXPECT_FALSE ( boost :: filesystem :: exists ( csvt_path ) ) ; EXPECT_TRUE ( boost :: filesystem :: exists ( survive_path ) ) ; }
Two uploads.
Two uploads .
//Upload a file successfully, it should not be deleted on second upload //this upload is supposed to fail //check that an error was returned //check that both files from the upload do not exist, but the file from the first upload is still there