-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_stats_test.cpp
More file actions
55 lines (46 loc) · 2.03 KB
/
server_stats_test.cpp
File metadata and controls
55 lines (46 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "gtest/gtest.h"
#include "request.hpp"
#include "response.hpp"
#include "server_stats.hpp"
#include "request_handler.hpp"
#include <string>
#include <limits.h>
#include <unistd.h>
namespace http {
namespace server {
TEST(ServerStatsTest, InsertHandler) {
ServerStats::getInstance().clearAllEntries();
ServerStats::getInstance().insertHandler("/echo", "echo_handler");
ServerStats::getInstance().insertHandler("/static1", "file_handler");
ServerStats::getInstance().insertHandler("/static2", "file_handler");
ServerStats::getInstance().insertHandler("/Status", "StatusHandler");
std::vector<std::pair<std::string, std::string>> hand = ServerStats::getInstance().getHandlers();
EXPECT_EQ(hand.size(), 4);
EXPECT_EQ(hand[0].first, "/echo");
EXPECT_EQ(hand[0].second, "echo_handler");
EXPECT_EQ(hand[1].first, "/static1");
EXPECT_EQ(hand[1].second, "file_handler");
EXPECT_EQ(hand[2].first, "/static2");
EXPECT_EQ(hand[2].second, "file_handler");
EXPECT_EQ(hand[3].first, "/Status");
EXPECT_EQ(hand[3].second, "StatusHandler");
}
TEST(ServerStatsTest, InsertRequest) {
ServerStats::getInstance().insertRequest("/echo", Response::ResponseCode::ok);
ServerStats::getInstance().insertRequest("/static1", Response::ResponseCode::ok);
ServerStats::getInstance().insertRequest("/static2", Response::ResponseCode::not_found);
ServerStats::getInstance().insertRequest("/Status", Response::ResponseCode::ok);
std::vector<std::pair<std::string, Response::ResponseCode>> req = ServerStats::getInstance().getRequests();
int totalNum = ServerStats::getInstance().getNumRequests();
EXPECT_EQ(totalNum, 4);
EXPECT_EQ(req[0].first, "/echo");
EXPECT_EQ(req[0].second, Response::ResponseCode::ok);
EXPECT_EQ(req[1].first, "/static1");
EXPECT_EQ(req[1].second, Response::ResponseCode::ok);
EXPECT_EQ(req[2].first, "/static2");
EXPECT_EQ(req[2].second, Response::ResponseCode::not_found);
EXPECT_EQ(req[3].first, "/Status");
EXPECT_EQ(req[3].second, Response::ResponseCode::ok);
}
}
}