diff --git a/src/tawashi/CMakeLists.txt b/src/tawashi/CMakeLists.txt index 24bb117..478491c 100644 --- a/src/tawashi/CMakeLists.txt +++ b/src/tawashi/CMakeLists.txt @@ -60,6 +60,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1 PUBLIC $<$:SPDLOG_DEBUG_ON> PUBLIC $<$:SPDLOG_TRACE_ON> + PUBLIC tawashi_virtual_testing$<$:=virtual> + PUBLIC $<$:TAWASHI_WITH_TESTING> ) target_compile_options(${PROJECT_NAME} PRIVATE -fdiagnostics-color=always diff --git a/src/tawashi/response.cpp b/src/tawashi/response.cpp index ce0333b..716c9ee 100644 --- a/src/tawashi/response.cpp +++ b/src/tawashi/response.cpp @@ -17,7 +17,6 @@ #include "response.hpp" #include "settings_bag.hpp" -#include "tawashi_config.h" #include "duckhandy/stringize.h" #include "duckhandy/lexical_cast.hpp" #include "pathname/pathname.hpp" diff --git a/src/tawashi/response.hpp b/src/tawashi/response.hpp index 7e16034..3edc5f7 100644 --- a/src/tawashi/response.hpp +++ b/src/tawashi/response.hpp @@ -51,7 +51,7 @@ namespace tawashi { const cgi::Env& cgi_env() const; const std::string& base_uri() const; virtual boost::string_ref page_basename() const = 0; - const Storage& storage() const; + tawashi_virtual_testing const Storage& storage() const; const SettingsBag& settings() const; virtual std::string load_mustache() const; HttpHeader make_redirect (HttpStatusCodes parCode, const std::string& parLocation); diff --git a/src/tawashi/storage.cpp b/src/tawashi/storage.cpp index 8c918fa..9417f24 100644 --- a/src/tawashi/storage.cpp +++ b/src/tawashi/storage.cpp @@ -128,4 +128,10 @@ namespace tawashi { return pastie; } + +#if defined(TAWASHI_WITH_TESTING) + const SettingsBag& Storage::settings() const { + return *m_settings; + } +#endif } //namespace tawashi diff --git a/src/tawashi/storage.hpp b/src/tawashi/storage.hpp index 9b02083..91a4d56 100644 --- a/src/tawashi/storage.hpp +++ b/src/tawashi/storage.hpp @@ -40,19 +40,23 @@ namespace tawashi { }; explicit Storage (const Kakoune::SafePtr& parSettings); - ~Storage(); + tawashi_virtual_testing ~Storage(); - void connect_async(); - bool is_connected() const; - void finalize_connection(); - SubmissionResult submit_pastie ( + tawashi_virtual_testing void connect_async(); + tawashi_virtual_testing bool is_connected() const; + tawashi_virtual_testing void finalize_connection(); + tawashi_virtual_testing SubmissionResult submit_pastie ( const boost::string_ref& parText, uint32_t parExpiry, const boost::string_ref& parLang, const std::string& parRemoteIP ) const; - boost::optional retrieve_pastie (const boost::string_ref& parToken) const; + tawashi_virtual_testing boost::optional retrieve_pastie (const boost::string_ref& parToken) const; + +#if defined(TAWASHI_WITH_TESTING) + const SettingsBag& settings() const; +#endif private: std::unique_ptr m_redis; diff --git a/src/tawashi/submit_paste_response.cpp b/src/tawashi/submit_paste_response.cpp index c60c5f0..df92aa6 100644 --- a/src/tawashi/submit_paste_response.cpp +++ b/src/tawashi/submit_paste_response.cpp @@ -133,9 +133,11 @@ namespace tawashi { oss << *token; if (not lang.empty()) oss << '?' << lang; - statuslog->info("Pastie token=\"{}\" redirect=\"{}\"", *token, oss.str()); - return this->make_success_response(oss.str()); + std::string redirect = oss.str(); + statuslog->info("Pastie token=\"{}\" redirect=\"{}\"", *token, redirect); + + return this->make_success_response(std::move(redirect)); } else { statuslog->info("Empty pastie token (possibly due to a previous failure)");