test/unittests/uploader.cpp
/*
 * Runnig twice the same upload (with append_upload=false), first successfull, second throwing an exception.
 */
Runnig twice the same upload (with append_upload=false), first successfull, second throwing an exception.
Runnig twice the same upload ( with append_upload = false ) first successfull second throwing an exception .
TEST_F(UploaderTest, same_upload_twice){
    {
        std::stringstream fake_in;
        fake_in << two_file_request_p1;
        fake_in << sessiontoken;
        fake_in << two_file_request_p2;
        std::stringstream fake_out;
        UploadService service(fake_in.rdbuf(), fake_out.rdbuf(), std::cerr.rdbuf());
        service.run();
        while (fake_out.good() && fake_out.peek() != '{') {
            fake_out.get();
        }
        if (!fake_out.good()) {
            EXPECT_TRUE(false);
            return;
        }
        Json::Value result_json;
        fake_out >> result_json;
        EXPECT_TRUE(result_json["result"].asBool());
        EXPECT_EQ(result_json["upload_name"], "test_upload");
        boost::filesystem::path path_test(temp_dir_name);
        path_test /= userID;
        path_test /= "test_upload";
        path_test /= "hello.csv";
        EXPECT_TRUE(boost::filesystem::exists(path_test));
        EXPECT_TRUE(boost::filesystem::is_regular_file(path_test));
    }
    {
        std::stringstream fake_in;
        fake_in << two_file_request_p1;
        fake_in << sessiontoken;
        fake_in << two_file_request_p2;
        std::stringstream fake_out;
        UploadService service(fake_in.rdbuf(), fake_out.rdbuf(), std::cerr.rdbuf());
        service.run();
        EXPECT_EQ(fake_out.str(), "Status: 500 Internal Server Error\r\n"
                "Content-type: text/plain\r\n"
                "\r\nInvalid upload: UploaderException: Upload with same name already exists");
    }
}
TEST_F ( UploaderTest , same_upload_twice ) { { std :: stringstream fake_in ; fake_in << two_file_request_p1 ; fake_in << sessiontoken ; fake_in << two_file_request_p2 ; std :: stringstream fake_out ; UploadService service ( fake_in . rdbuf ( ) , fake_out . rdbuf ( ) , std :: cerr . rdbuf ( ) ) ; service . run ( ) ; while ( fake_out . good ( ) && fake_out . peek ( ) != ' ' ) { fake_out . get ( ) ; } if ( ! fake_out . good ( ) ) { EXPECT_TRUE ( false ) ; return ; } Json :: Value result_json ; fake_out >> result_json ; EXPECT_TRUE ( result_json [ " " ] . asBool ( ) ) ; EXPECT_EQ ( result_json [ " " ] , " " ) ; boost :: filesystem :: path path_test ( temp_dir_name ) ; path_test /= userID ; path_test /= " " ; path_test /= " " ; EXPECT_TRUE ( boost :: filesystem :: exists ( path_test ) ) ; EXPECT_TRUE ( boost :: filesystem :: is_regular_file ( path_test ) ) ; } { std :: stringstream fake_in ; fake_in << two_file_request_p1 ; fake_in << sessiontoken ; fake_in << two_file_request_p2 ; std :: stringstream fake_out ; UploadService service ( fake_in . rdbuf ( ) , fake_out . rdbuf ( ) , std :: cerr . rdbuf ( ) ) ; service . run ( ) ; EXPECT_EQ ( fake_out . str ( ) , " \r \n " " \r \n " " \r \n " ) ; } }
Runnig twice the same upload (with append_upload=false), first successfull, second throwing an exception.
Runnig twice the same upload ( with append_upload = false ) first successfull second throwing an exception .
//test upload. sessiontoken is inserted into test strings. //read the header from the response, until the response json starts. //second test with same files and they already exist, should throw exception, that's returned as 500 response at the moment.