diff --git a/toREST/tests/http_test.cpp b/toREST/tests/http_test.cpp
index f8b1bdc..f5a9e63 100644
--- a/toREST/tests/http_test.cpp
+++ b/toREST/tests/http_test.cpp
@@ -3,62 +3,62 @@
using namespace std;
-TEST_CASE("Check http status"){
- auto out=http::code(http::ok);
+TEST_CASE("Check http status") {
+ auto out = http::code(http::ok);
REQUIRE(out.first == 200);
REQUIRE(out.second == "OK");
}
-SCENARIO("http response"){
- auto response=http::response();
+SCENARIO("http response") {
+ auto response = http::response();
std::stringstream ss;
- GIVEN("we stream our response without setting given any data"){
+ GIVEN("we stream our response without setting given any data") {
ss << response;
THEN("the response will default to 200")
- REQUIRE(ss.str()=="HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\n200 OK"s);
+ REQUIRE(ss.str() == "HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\n200 OK"s);
}
- GIVEN("we stream our data with the response status set to 404"){
+ GIVEN("we stream our data with the response status set to 404") {
response.set_status(http::not_found);
ss << response;
- THEN("the default 404 response will be sent instead"){
- REQUIRE(ss.str()=="HTTP/1.1 404 Not Found\r\nContent-Length: 13\r\n\r\n404 Not Found"s);
+ THEN("the default 404 response will be sent instead") {
+ REQUIRE(ss.str() == "HTTP/1.1 404 Not Found\r\nContent-Length: 13\r\n\r\n404 Not Found"s);
}
}
- GIVEN("we stream our response with the status set to 204 No Content"){
+ GIVEN("we stream our response with the status set to 204 No Content") {
response.set_status(http::no_content);
ss << response;
THEN("the response has no content header set")
- REQUIRE(ss.str()=="HTTP/1.1 204 No Content\r\n\r\n"s);
+ REQUIRE(ss.str() == "HTTP/1.1 204 No Content\r\n\r\n"s);
}
- GIVEN("we stream our response with the body set"){
+ GIVEN("we stream our response with the body set") {
response.set_body("Easter eggs, everywhere! ye"s);
ss << response;
THEN("our response contains the appropriate headers")
- REQUIRE(ss.str()=="HTTP/1.1 200 OK\r\nContent-Length: 103\r\n\r\nEaster eggs, everywhere! ye"s);
+ REQUIRE(ss.str() == "HTTP/1.1 200 OK\r\nContent-Length: 103\r\n\r\nEaster eggs, everywhere! ye"s);
}
- GIVEN("we add a header to the resource"){
+ GIVEN("we add a header to the resource") {
response.set_body("Nothing"s);
- response.add_header(http::header("Strict-Error"s,"on"s));
+ response.add_header(http::header("Strict-Error"s, "on"s));
ss << response;
THEN("our response contains the appropriate headers")
- REQUIRE(ss.str()=="HTTP/1.1 200 OK\r\nStrict-Error: on\r\nContent-Length: 7\r\n\r\nNothing"s);
+ REQUIRE(ss.str() == "HTTP/1.1 200 OK\r\nStrict-Error: on\r\nContent-Length: 7\r\n\r\nNothing"s);
}
}
-SCENARIO("Stream http responses with a json response"){
- auto response=http::response();
+SCENARIO("Stream http responses with a json response") {
+ auto response = http::response();
std::stringstream ss;
- GIVEN("we set the response code to 404 and stream our response"){
+ GIVEN("we set the response code to 404 and stream our response") {
response.set_status(http::not_found);
- response.set_body({{"code",404},{"status","Not Found"}});
+ response.set_body({{"code", 404}, {"status", "Not Found"}});
ss << response;
THEN("our response is valid json and the resoinse code is 404")
- REQUIRE(ss.str()=="HTTP/1.1 404 Not Found\r\nContent-Type: application/json\r\nContent-Length: 33\r\n\r\n{\"code\":404,\"status\":\"Not Found\"}"s);
+ REQUIRE(ss.str() == "HTTP/1.1 404 Not Found\r\nContent-Type: application/json\r\nContent-Length: 33\r\n\r\n{\"code\":404,\"status\":\"Not Found\"}"s);
}
- GIVEN("we stream our response with the body set"){
+ GIVEN("we stream our response with the body set") {
response.set_body(nlohmann::json::object());
ss << response;
THEN("our response contains the appropriate headers")
- REQUIRE(ss.str()=="HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 2\r\n\r\n{}"s);
+ REQUIRE(ss.str() == "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 2\r\n\r\n{}"s);
}
}
diff --git a/toREST/tests/include/ServerContext.hpp b/toREST/tests/include/ServerContext.hpp
index 3b86862..1f9c13e 100644
--- a/toREST/tests/include/ServerContext.hpp
+++ b/toREST/tests/include/ServerContext.hpp
@@ -1,9 +1,9 @@
#ifndef _TR_TEST_SERVER_CONTEXT_HPP_
#define _TR_TEST_SERVER_CONTEXT_HPP_
-#include
-#include
#include
#include
+#include
+#include
class TestRequest {
public:
diff --git a/toREST/tests/include/SessionContext.hpp b/toREST/tests/include/SessionContext.hpp
index 1cfe8d7..f636320 100644
--- a/toREST/tests/include/SessionContext.hpp
+++ b/toREST/tests/include/SessionContext.hpp
@@ -1,9 +1,9 @@
#ifndef _TR_TEST_SESSION_CONTEXT_HPP_
#define _TR_TEST_SESSION_CONTEXT_HPP_
+#include
#include
#include
-#include
class TestSessionSettings {
public:
@@ -21,7 +21,6 @@ public:
int get_int(int type) const;
bool get_bool(int type);
std::string get_str(int type);
-
};
class TestSession {
@@ -37,7 +36,7 @@ public:
void resume();
int listen_port();
bool is_dht_running() const;
- std::vector& get_torrents();
+ std::vector &get_torrents();
void apply_settings(TestSessionSettings settings);
};
diff --git a/toREST/tests/session_test.cpp b/toREST/tests/session_test.cpp
index cff486f..4e613da 100644
--- a/toREST/tests/session_test.cpp
+++ b/toREST/tests/session_test.cpp
@@ -3,8 +3,8 @@
#include
#include
-const nlohmann::json ok_data = {{"dht_enabled", true}, {"down_limit", 0}, {"paused", false}, {"port", 0}, {"torrents", 0}, {"up_limit", 0}};
-const nlohmann::json ok_data_paused = {{"dht_enabled", true}, {"down_limit", 0}, {"paused", true}, {"port", 0}, {"torrents", 0}, {"up_limit", 0}};
+const nlohmann::json ok_data = {{"dht_enabled", true}, {"down_limit", 0}, {"paused", false}, {"port", 0}, {"torrents", 0}, {"up_limit", 0}};
+const nlohmann::json ok_data_paused = {{"dht_enabled", true}, {"down_limit", 0}, {"paused", true}, {"port", 0}, {"torrents", 0}, {"up_limit", 0}};
SCENARIO("We are running a GET /session resource") {
auto torrent_session = TestSession();
diff --git a/toREST/tests/stubs/SessionContext.cpp b/toREST/tests/stubs/SessionContext.cpp
index 259e62d..87aed05 100644
--- a/toREST/tests/stubs/SessionContext.cpp
+++ b/toREST/tests/stubs/SessionContext.cpp
@@ -60,7 +60,7 @@ int TestSession::listen_port() {
bool TestSession::is_dht_running() const {
return settings_.enable_dht_;
}
-std::vector& TestSession::get_torrents() {
+std::vector &TestSession::get_torrents() {
return torrents;
}
void TestSession::apply_settings(TestSessionSettings settings) {
diff --git a/toREST/tests/torrents_test.cpp b/toREST/tests/torrents_test.cpp
index 741ab60..b3671fc 100644
--- a/toREST/tests/torrents_test.cpp
+++ b/toREST/tests/torrents_test.cpp
@@ -6,13 +6,12 @@
using namespace std;
const nlohmann::json torrent = {
- {"hash", "12a"},
- {"paused", false},
- {"seeding", false},
- {"state", 0},
- {"priority", 0},
- {"name", "Arch"}
-};
+ {"hash", "12a"},
+ {"paused", false},
+ {"seeding", false},
+ {"state", 0},
+ {"priority", 0},
+ {"name", "Arch"}};
SCENARIO("We are running a GET /session/torrents resource") {
auto torrent_session = TestSession();
@@ -31,19 +30,18 @@ SCENARIO("We are running a GET /session/torrents resource") {
WHEN("we recive a valid request") {
GIVEN("we have no torrents") {
THEN("the server should reply with an empty array") {
- tr::session::torrents::get(torrent_session,response,request);
- CommonResponse::ok(response, {{"torrents", nlohmann::json::array()}});
+ tr::session::torrents::get(torrent_session, response, request);
+ CommonResponse::ok(response, {{"torrents", nlohmann::json::array()}});
}
}
- GIVEN("we have at least one torrent"){
- auto t_torrent=TestTorrent();
+ GIVEN("we have at least one torrent") {
+ auto t_torrent = TestTorrent();
torrent_session.get_torrents().emplace_back(t_torrent);
- THEN("the server should reply with an array of torrents"){
- tr::session::torrents::get(torrent_session,response,request);
+ THEN("the server should reply with an array of torrents") {
+ tr::session::torrents::get(torrent_session, response, request);
CommonResponse::ok(response, {{"torrents", {torrent}}});
- }
+ };
}
}
}
-
}
\ No newline at end of file