Skip to content

Commit 7900a0e

Browse files
authored
Merge pull request #17 from Dan-Tan/test-api-key-path
feat: add ability to add custom path for api keys for testing.
2 parents 9420d3f + 5340ff0 commit 7900a0e

2 files changed

Lines changed: 42 additions & 19 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ target_link_options(riot-cpp PRIVATE -fsanitize=address -static-libasan)
2525

2626
add_executable(client_tests test/client_tests.cpp test/simdjson.cpp)
2727
target_link_libraries(client_tests riot-cpp)
28-
target_link_libraries(client_tests Catch2::Catch2WithMain)
28+
target_link_libraries(client_tests Catch2::Catch2)
2929

3030
target_compile_options(client_tests PRIVATE -fsanitize=address -static-libasan)
3131
target_link_options(client_tests PRIVATE -fsanitize=address -static-libasan)

test/client_tests.cpp

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define CATCH_CONFIG_RUNNER
2+
#include <catch2/catch_session.hpp>
13
#include <catch2/catch_test_macros.hpp>
24
#include <iostream>
35
#include <ctime>
@@ -7,10 +9,31 @@
79
#include "../src/riot-cpp/client/client.h"
810
#include "json.hpp"
911

10-
#define CONFIG "../../.api_keys/riot_config.json", "../test/log_file.txt", logging::LEVEL::DEBUG, true
12+
static std::string api_key_path;
13+
14+
int main(int argc, char* argv[]) {
15+
Catch::Session session;
16+
17+
using namespace Catch::Clara;
18+
auto cli = session.cli() | Opt(api_key_path, "api_key_path")["-p"]["--path"]("Path to riot_config.json");
19+
session.cli(cli);
20+
21+
int returnCode = session.applyCommandLine(argc, argv);
22+
if (returnCode != 0)
23+
return returnCode;
24+
25+
if (api_key_path.empty()) {
26+
api_key_path = "../../.api_keys/riot_config.json";
27+
}
28+
29+
return session.run();
30+
}
31+
1132
namespace riotcpp {
1233
using namespace client;
1334

35+
using namespace client;
36+
1437
static std::string ROUTING = "KR";
1538
static std::string SUMMONER_ID;
1639
static std::string PUUID;
@@ -21,7 +44,7 @@ using json = nlohmann::json;
2144

2245
TEST_CASE( "ACCOUNT_V1 QUERIES") {
2346
std::cout << "TESTING ACCOUNT_V1 QUERIES" << '\n';
24-
RiotApiClient test_client(CONFIG);
47+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
2548

2649
std::vector<std::string> region = {"AMERICAS", "ASIA", "EUROPE"};
2750
std::string puuid; // puuid is key specific
@@ -59,7 +82,7 @@ TEST_CASE( "ACCOUNT_V1 QUERIES") {
5982

6083
TEST_CASE( "LEAGUE_V4 QUERIES") {
6184
std::cout << "TESTING LEAGUE_V4 QUERIES" << '\n';
62-
RiotApiClient test_client(CONFIG);
85+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
6386

6487
std::string region = "na1";
6588
std::vector<std::string> queue = {"RANKED_SOLO_5x5", "RANKED_FLEX_SR"};
@@ -131,7 +154,7 @@ TEST_CASE( "LEAGUE_V4 QUERIES") {
131154

132155
TEST_CASE(" SUMMONER QUERIES ") {
133156
std::cout << "TESTING SUMMONER QUERIES " << '\n';
134-
RiotApiClient test_client(CONFIG);
157+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
135158

136159
std::string region = "kr";
137160
std::string summoner_name = "Hide on bush";
@@ -160,7 +183,7 @@ TEST_CASE(" SUMMONER QUERIES ") {
160183

161184
TEST_CASE( "MATCH QUERIES" ) {
162185
std::cout << "TESTING MATCH QUERIES" << '\n';
163-
RiotApiClient test_client(CONFIG);
186+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
164187

165188
std::string region = "ASIA";
166189
std::string match_id = "KR_6279823690";
@@ -181,7 +204,7 @@ TEST_CASE( "MATCH QUERIES" ) {
181204

182205
TEST_CASE("CHAMPION-MASTERY-V4 QUERIES") {
183206
std::cout << "TESTING CHAMPION-MASTERY-V4 QUERIES" << '\n';
184-
RiotApiClient test_client(CONFIG);
207+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
185208

186209
const int champion_id = 1;
187210
std::string endpoint = "CHAMPION-MASTERY-V4";
@@ -217,7 +240,7 @@ TEST_CASE("CHAMPION-MASTERY-V4 QUERIES") {
217240

218241
TEST_CASE("CHAMPION-V3") {
219242
std::cout << "TESTING CHAMPION-V3" << '\n';
220-
RiotApiClient test_client(CONFIG);
243+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
221244

222245
json_ptr result;
223246
json doc;
@@ -230,7 +253,7 @@ TEST_CASE("CHAMPION-V3") {
230253

231254
TEST_CASE("LOL-CHALLENGES-V1") {
232255
std::cout << "TESTING LOL-CHALLENGES-V1" << '\n';
233-
RiotApiClient test_client(CONFIG);
256+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
234257

235258
const int challenge_id = 1;
236259
std::string level = "HIGHEST";
@@ -263,7 +286,7 @@ TEST_CASE("LOL-CHALLENGES-V1") {
263286
}
264287
TEST_CASE("LOL-STATUS") {
265288
std::cout << "TESTING LOL-STATUS" << '\n';
266-
RiotApiClient test_client(CONFIG);
289+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
267290

268291
json_ptr result;
269292
json doc;
@@ -279,7 +302,7 @@ TEST_CASE("LOL-STATUS") {
279302
}
280303
TEST_CASE("LOR-MATCH-V1") {
281304
std::cout << "TESTING LOR-MATCH-V1" << '\n';
282-
RiotApiClient test_client(CONFIG);
305+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
283306

284307
json_ptr result;
285308
std::string endpoint = "LOR-MATCH-V1";
@@ -300,7 +323,7 @@ std::cout << "TESTING LOR-MATCH-V1" << '\n';
300323
}
301324
TEST_CASE("LOR-RANKED-V1") {
302325
std::cout << "TESTING LOR-RANKED-V1" << '\n';
303-
RiotApiClient test_client(CONFIG);
326+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
304327

305328
json_ptr result;
306329
json doc;
@@ -312,7 +335,7 @@ TEST_CASE("LOR-RANKED-V1") {
312335
}
313336
TEST_CASE("LOR-STATUS-V1") {
314337
std::cout << "TESTING LOR-STATUS-V1" << '\n';
315-
RiotApiClient test_client(CONFIG);
338+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
316339

317340
json_ptr result;
318341
json doc;
@@ -327,7 +350,7 @@ TEST_CASE("LOR-STATUS-V1") {
327350
}
328351
TEST_CASE("SPECTATOR-V4") {
329352
std::cout << "TESTING SPECTATOR-V4" << '\n';
330-
RiotApiClient test_client(CONFIG);
353+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
331354

332355
json_ptr result;
333356
std::string endpoint = "SPECTATOR-V4";
@@ -365,7 +388,7 @@ TEST_CASE("SPECTATOR-V4") {
365388
}
366389
TEST_CASE("TFT-LEAGUE-V1") {
367390
std::cout << "TESTING TFT-LEAGUE-V1" << '\n';
368-
RiotApiClient test_client(CONFIG);
391+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
369392

370393
json_ptr result;
371394
std::string endpoint = "TFT-LEAGUE-V1";
@@ -423,7 +446,7 @@ TEST_CASE("TFT-LEAGUE-V1") {
423446
}
424447
TEST_CASE("TFT-MATCH-V1") {
425448
std::cout << "TESTING TFT-MATCH-V1" << '\n';
426-
RiotApiClient test_client(CONFIG);
449+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
427450

428451
json_ptr result;
429452
json doc;
@@ -459,7 +482,7 @@ TEST_CASE("TFT-MATCH-V1") {
459482
}
460483
TEST_CASE("TFT-STATUS-V1") {
461484
std::cout << "TESTING TFT-STATUS-V1" << '\n';
462-
RiotApiClient test_client(CONFIG);
485+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
463486

464487
json_ptr result;
465488
json doc;
@@ -472,7 +495,7 @@ TEST_CASE("TFT-STATUS-V1") {
472495
}
473496
TEST_CASE("TFT-SUMMONER-V1") {
474497
std::cout << "TESTING TFT-SUMMONER-V1" << '\n';
475-
RiotApiClient test_client(CONFIG);
498+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
476499

477500
json_ptr result;
478501
json doc;
@@ -503,7 +526,7 @@ TEST_CASE("TFT-SUMMONER-V1") {
503526
}
504527
TEST_CASE("VAL-CONTENT-V1") {
505528
std::cout << "TESTING VAL-CONTENT-V1" << '\n';
506-
RiotApiClient test_client(CONFIG);
529+
RiotApiClient test_client(api_key_path, "../test/log_file.txt", logging::LEVEL::DEBUG, true);
507530

508531
json_ptr result;
509532
json doc;

0 commit comments

Comments
 (0)