From 0ffd41c851cc2b3f936a0d89cc58a948a024b595 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 14 Apr 2019 23:08:44 +0200 Subject: [PATCH] Allowed the setting of the instance for testing. Via the environment variable MASTODON_CPP_INSTANCE. --- README.md | 11 ++++++++-- tests/test_api_v1_accounts_id.cpp | 8 ++++--- ...est_api_v1_accounts_update_credentials.cpp | 8 ++++--- ...est_api_v1_accounts_verify_credentials.cpp | 8 ++++--- tests/test_api_v1_instance.cpp | 21 +++++++++++-------- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ea1e775..8a48e59 100644 --- a/README.md +++ b/README.md @@ -204,8 +204,15 @@ cmake options: * `-DWITH_DEB=YES` if you want to be able to generate a deb-package * `-DWITH_RPM=YES` if you want to be able to generate an rpm-package -You can run the tests with `ctest` inside the build directory. -To install, run `make install`. +Install with `make install`. + +### Tests + +You can run the tests with `ctest` inside the build directory. You need to set +the environment variable `MASTODON_CPP_ACCESS_TOKEN` to an access token with the +scopes *read*, *write*, *follow* and *push* for some tests. +You can select the instance to use with `MASTODON_CPP_INSTANCE`, the default is +*likeable.space*. ### Packages diff --git a/tests/test_api_v1_accounts_id.cpp b/tests/test_api_v1_accounts_id.cpp index ca38625..cdf7b92 100644 --- a/tests/test_api_v1_accounts_id.cpp +++ b/tests/test_api_v1_accounts_id.cpp @@ -26,15 +26,17 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("id and return_call") + GIVEN ("instance, id and return_call") { + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); const string id = "9hnrrVPriLiLVAhfVo"; return_call ret; bool exception = false; GIVEN ("Mastodon::API") { - Mastodon::API masto("likeable.space", ""); + Mastodon::API masto(instance, ""); bool username_found = false; WHEN ("/api/v1/accounts/" + id + " is called") @@ -68,7 +70,7 @@ SCENARIO ("/api/v1/accounts/:id can be called successfully", GIVEN ("Mastodon::Easy::API") { - Mastodon::Easy::API masto("likeable.space", ""); + Mastodon::Easy::API masto(instance, ""); Easy::Account account; WHEN ("/api/v1/accounts/" + id + " is called") diff --git a/tests/test_api_v1_accounts_update_credentials.cpp b/tests/test_api_v1_accounts_update_credentials.cpp index 5a7bbf0..73bf5af 100644 --- a/tests/test_api_v1_accounts_update_credentials.cpp +++ b/tests/test_api_v1_accounts_update_credentials.cpp @@ -27,8 +27,10 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/update_credentials can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("access token and return_call") + GIVEN ("instance, access token and return_call") { + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); return_call ret; bool exception = false; @@ -38,7 +40,7 @@ SCENARIO ("/api/v1/accounts/update_credentials can be called successfully", GIVEN ("Mastodon::API") { - Mastodon::API masto("likeable.space", access_token); + Mastodon::API masto(instance, access_token); WHEN ("/api/v1/accounts/update_credentials is called") { @@ -71,7 +73,7 @@ SCENARIO ("/api/v1/accounts/update_credentials can be called successfully", GIVEN ("Mastodon::Easy::API") { - Mastodon::Easy::API masto("likeable.space", access_token); + Mastodon::Easy::API masto(instance, access_token); Easy::Account account; WHEN ("/api/v1/accounts/update_credentials is called") diff --git a/tests/test_api_v1_accounts_verify_credentials.cpp b/tests/test_api_v1_accounts_verify_credentials.cpp index 264b735..62f401c 100644 --- a/tests/test_api_v1_accounts_verify_credentials.cpp +++ b/tests/test_api_v1_accounts_verify_credentials.cpp @@ -27,8 +27,10 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/verify_credentials can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("access token and return_call") + GIVEN ("instance, access token and return_call") { + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); return_call ret; bool exception = false; @@ -38,7 +40,7 @@ SCENARIO ("/api/v1/accounts/verify_credentials can be called successfully", GIVEN ("Mastodon::API") { - Mastodon::API masto("likeable.space", access_token); + Mastodon::API masto(instance, access_token); WHEN ("/api/v1/accounts/verify_credentials is called") { @@ -70,7 +72,7 @@ SCENARIO ("/api/v1/accounts/verify_credentials can be called successfully", GIVEN ("Mastodon::Easy::API") { - Mastodon::Easy::API masto("likeable.space", access_token); + Mastodon::Easy::API masto(instance, access_token); Easy::Account account; WHEN ("/api/v1/accounts/verify_credentials is called") diff --git a/tests/test_api_v1_instance.cpp b/tests/test_api_v1_instance.cpp index 02b3eae..699231c 100644 --- a/tests/test_api_v1_instance.cpp +++ b/tests/test_api_v1_instance.cpp @@ -26,14 +26,16 @@ using namespace Mastodon; SCENARIO ("/api/v1/instance can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("return_call") + GIVEN ("instance and return_call") { + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); return_call ret; bool exception = false; GIVEN ("Mastodon::API") { - Mastodon::API masto("likeable.space", ""); + Mastodon::API masto(instance, ""); bool uri_found = false; WHEN ("/api/v1/instance is called") @@ -41,8 +43,9 @@ SCENARIO ("/api/v1/instance can be called successfully", try { ret = masto.get(API::v1::instance); - uri_found = ret.answer.find( - "\"uri\":\"https://likeable.space\"") != std::string::npos; + uri_found = + ret.answer.find("\"uri\":\"https://likeable.space\"") + != std::string::npos; } catch (const std::exception &e) { @@ -66,15 +69,15 @@ SCENARIO ("/api/v1/instance can be called successfully", GIVEN ("Mastodon::Easy::API") { - Mastodon::Easy::API masto("likeable.space", ""); - Easy::Instance instance; + Mastodon::Easy::API masto(instance, ""); + Easy::Instance instance_; WHEN ("/api/v1/instance is called") { try { ret = masto.get(API::v1::instance); - instance = Easy::Instance(ret.answer); + instance_ = Easy::Instance(ret.answer); } catch (const std::exception &e) { @@ -91,11 +94,11 @@ SCENARIO ("/api/v1/instance can be called successfully", } THEN ("Answer is valid") { - REQUIRE(instance.valid()); + REQUIRE(instance_.valid()); } THEN ("The answer makes sense") { - REQUIRE(instance.uri() == "https://likeable.space"); + REQUIRE(instance_.uri() == "https://likeable.space"); } } }