-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add network interface test for telegram send message post test when r…
…unning locally.
- Loading branch information
Showing
4 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "testing/Test.h" | ||
#include "logging/Log.h" | ||
#include "logging/String.h" | ||
|
||
#include "network/NetworkInterface.h" | ||
#include "filesystem/File.h" | ||
|
||
#include <array> | ||
|
||
using namespace l; | ||
|
||
TEST(NetworkInterface, Setup) { | ||
|
||
std::stringstream telegramToken; | ||
if (!l::filesystem::read("tests/telegrambottoken.txt", telegramToken)) { | ||
return 0; | ||
} | ||
|
||
auto networkManager = l::network::CreateNetworkManager(2, false); | ||
auto networkInterface = l::network::CreateNetworkInterface(networkManager); | ||
|
||
std::string query = "bot"; | ||
query += telegramToken.str(); | ||
query += "/sendMessage?"; | ||
|
||
auto telegramHandler = [&]( | ||
bool success, | ||
std::string_view queryArguments, | ||
l::network::RequestStringStream& request) { | ||
TEST_TRUE_NO_RET(success, ""); | ||
|
||
LOG(LogInfo) << "Query arguments: '" << queryArguments << "'"; | ||
LOG(LogInfo) << request.GetResponse().str(); | ||
return l::concurrency::RunnableResult::SUCCESS; | ||
}; | ||
|
||
networkInterface->CreateInterface("Telegram", "https", "api.telegram.org"); | ||
networkInterface->CreateRequestTemplate<std::stringstream>("Telegram", "TradeFlowBot1", query, 1, 2000, 5, telegramHandler); | ||
|
||
std::string chatId = "6640331275"; // TradeFlowGroup | ||
std::string args; | ||
std::string message = "NetworkInterface"; | ||
args += "chat_id=" + chatId; | ||
args += "&text=" + message; | ||
|
||
networkInterface->SendRequest("Telegram", "TradeFlowBot1", args, 1, 2000, 5, nullptr); | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(20)); | ||
|
||
networkManager->ClearJobs(); | ||
networkManager->Shutdown(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters