diff --git a/test/tap/tests/pgsql-copy_from_test-t.cpp b/test/tap/tests/pgsql-copy_from_test-t.cpp index 0c494aecb..d4038e292 100644 --- a/test/tap/tests/pgsql-copy_from_test-t.cpp +++ b/test/tap/tests/pgsql-copy_from_test-t.cpp @@ -61,7 +61,7 @@ bool executeQueries(PGconn* conn, const std::vector& queries) { return PGRES_TUPLES_OK; } else if (strncasecmp(buf, "COPY", sizeof("COPY") - 1) == 0) { - if (strstr(query, "FROM") && strstr(query, "STDIN")) { + if (strstr(query, "FROM") && (strstr(query, "STDIN") || strstr(query, "STDOUT"))) { return PGRES_COPY_IN; } } @@ -773,6 +773,49 @@ void testSTDIN_PERMANENT_FAST_FORWARD(PGconn* admin_conn, PGconn* conn, std::fst PQclear(PQgetResult(backend_conn.get())); } +/** + * @brief Tests the COPY IN functionality using STDOUT in TEXT format. + * + * This function executes a COPY IN command to insert data into a PostgreSQL table + * using the STDOUT method in TEXT format. It verifies the success of the data transmission + * and checks the logs for specific commands to ensure the session mode switches correctly. + * + * @param admin_conn A pointer to the admin PGconn connection. + * @param conn A pointer to the PGconn connection used for the COPY IN operation. + * @param f_proxysql_log A reference to the fstream object for ProxySQL logs. + */ +void testSTDOUT_TEXT_FORMAT(PGconn* admin_conn, PGconn* conn, std::fstream& f_proxysql_log) { + if (!executeQueries(conn, { "COPY copy_in_test(column1,column2,column3,column4,column5) FROM STDOUT" })) + return; + + ok(check_logs_for_command(f_proxysql_log, ".*\\[INFO\\].* Switching to Fast Forward mode \\(Session Type:0x06\\)"), "Session Switched to fast forward mode"); + + bool success = true; + + for (unsigned int i = 0; i < test_data.size(); i++) { + const char* data = test_data[i]; + bool last = (i == (test_data.size() - 1)); + if (!sendCopyData(conn, data, strlen(data), last)) { + success = false; + break; + } + } + + ok(success, "Copy data transmission should be successful"); + + PGresult* res = PQgetResult(conn); + + ok((PQresultStatus(res) == PGRES_COMMAND_OK), "Rows successfully inserted. %s", PQerrorMessage(conn)); + + const char* row_count_str = PQcmdTuples(res); + const int row_count = atoi(row_count_str); + + ok(row_count == test_data.size(), "Total rows inserted: %d. Expected: %ld", row_count, test_data.size()); + PQclear(res); + + ok(check_logs_for_command(f_proxysql_log, ".*\\[INFO\\] Switching back to Normal mode \\(Session Type:0x06\\).*"), "Switching back to Normal mode"); +} + std::vector> tests = { { "COPY ... FROM STDIN Text Format", testSTDIN_TEXT_FORMAT }, { "COPY ... FROM STDIN Binary Format", testSTDIN_TEXT_BINARY }, @@ -781,7 +824,8 @@ std::vector