You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.5 KiB
76 lines
2.5 KiB
#include <Catch/fakeit.hpp> |
|
#include <fakeserver.hpp> |
|
#include <session.hpp> |
|
|
|
using namespace std; |
|
|
|
class TestTorrent {}; |
|
class TestRequest : public std::stringstream {}; |
|
class TestResponse : public std::stringstream {}; |
|
|
|
class TestSessionSettings { |
|
public: |
|
const int download_rate_limit = 1; |
|
const int upload_rate_limit = 2; |
|
int get_int(int type) const { |
|
return 0; |
|
} |
|
}; |
|
|
|
class TestTorrentSession { |
|
public: |
|
bool valid = false; |
|
bool paused = false; |
|
bool dht_running = true; |
|
bool is_valid() { |
|
return valid; |
|
} |
|
TestSessionSettings get_settings() { |
|
return TestSessionSettings(); |
|
} |
|
bool is_paused() { |
|
return paused; |
|
} |
|
int listen_port() { |
|
return 0; |
|
} |
|
int is_dht_running() { |
|
return dht_running; |
|
} |
|
std::vector<TestTorrent> get_torrents() const { |
|
return std::vector<TestTorrent>(); |
|
} |
|
}; |
|
|
|
const std::string service_unavailable_json = "HTTP/1.1 503 Service Unavailable\r\nContent-Type: application/json\r\nContent-Length: 43\r\n\r\n{\"code\":503,\"status\":\"Service Unavailable\"}"; |
|
const std::string ok_json = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 82\r\n\r\n{\"dht_enabled\":1,\"down_limit\":0,\"paused\":false,\"port\":0,\"torrents\":0,\"up_limit\":0}"; |
|
const std::string ok_json_paused = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 81\r\n\r\n{\"dht_enabled\":1,\"down_limit\":0,\"paused\":true,\"port\":0,\"torrents\":0,\"up_limit\":0}"; |
|
|
|
SCENARIO("We recive a GET request to the /session resource") { |
|
auto torrent_session = TestTorrentSession(); |
|
auto response = std::make_shared<TestResponse>(); |
|
GIVEN("the session is invalid") { |
|
auto request = std::make_shared<TestResponse>(); |
|
tr::session::get(torrent_session, response, request); |
|
THEN("the server should reply with service unavailable") { |
|
REQUIRE(response->str() == service_unavailable_json); |
|
} |
|
} |
|
GIVEN("the session is valid") { |
|
auto request = std::make_shared<TestResponse>(); |
|
torrent_session.valid = true; |
|
tr::session::get(torrent_session, response, request); |
|
THEN("the server should reply with service unavailable") { |
|
REQUIRE(response->str() == ok_json); |
|
} |
|
} |
|
GIVEN("the session is valid") { |
|
auto request = std::make_shared<TestResponse>(); |
|
torrent_session.valid = true; |
|
torrent_session.paused = true; |
|
tr::session::get(torrent_session, response, request); |
|
THEN("the server should reply with service unavailable") { |
|
REQUIRE(response->str() == ok_json_paused); |
|
} |
|
} |
|
}
|
|
|