FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: add stack print out test · expresscpp/expresscpp@e3f7650 · GitHub

Commit e3f7650

Browse files
committed
test: add stack print out test
1 parent d90530a commit e3f7650

8 files changed

Lines changed: 31 additions & 16 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ project(expresscpp LANGUAGES CXX)
44

55
execute_process(COMMAND git
66
describe
7+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
8+
RESULT_VARIABLE retcode
79
OUTPUT_VARIABLE PROJECT_VERSION)
10+
if(NOT "${retcode}" STREQUAL "0")
11+
set(PROJECT_VERSION "0.0.0")
12+
message(STATUS "could not get git tag, setting version to ${PROJECT_VERSION}")
13+
endif()
814

915
###
1016
### options

‎doc/debug.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
```bash
66
# returns a json object containing the registered routes and handlers
7-
curl localhost:8080/debug
7+
curl localhost:8081/debug
88
```

‎example/simple_static_file_server.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main() {
3737
expresscpp->Use(expresscpp->GetStaticFileProvider(doc_root));
3838

3939
// start listening for requests and block until ctrl+C
40-
const uint16_t port = 8080u;
40+
const uint16_t port = 8081u;
4141
expresscpp
4242
->Listen(port, []() { std::cout << "Example app listening on port " << port << std::endl; })
4343
.Block();

‎test/hello_world.cpp‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#include "gtest/gtest.h"
2+
#include "nlohmann/json.hpp"
23

34
#include "expresscpp/expresscpp.hpp"
45
#include "expresscpp/types.hpp"
56
#include "test_utils.hpp"
67

8+
using namespace std::literals;
9+
710
// Performs an HTTP GET and prints the response
811
TEST(HelloWorld, GetRequest) {
912
auto expresscpp = std::make_shared<ExpressCpp>();
1013

11-
expresscpp->Listen(8080, []() {
14+
expresscpp->Listen(8081, []() {
1215
const auto s = getResponse("/", boost::beast::http::verb::get);
1316
EXPECT_GE(s.size(), 0);
1417
});
@@ -22,20 +25,24 @@ TEST(HelloWorld, UseRouter) {
2225
res->Json(R"({"status":"ok"})");
2326
});
2427

25-
expresscpp->Get("/api/v0/users", [](auto req, auto res) {
26-
std::cout << req->path_ << std::endl;
27-
res->Json(R"({"users":
28+
const auto json_response = R"({"users":
2829
[
2930
{"id": "39811e5d-cb4b-4dcf-a857-df3813fa89f3"},
3031
{"id": "4edfc753-b817-42d5-9266-d045f8945e2e"}
3132
]
32-
})");
33-
});
33+
})"sv;
3434

35-
// TODO: add here a request and expectation
35+
expresscpp->Get("/api/v0/users", [=](auto req, auto res) {
36+
std::cout << req->path_ << std::endl;
37+
res->Json(json_response);
38+
});
3639

37-
expresscpp->Listen(8080, []() {
40+
expresscpp->Listen(8081, [=]() {
3841
const auto s = getResponse("/", boost::beast::http::verb::get);
39-
EXPECT_GE(s.size(), 0);
42+
EXPECT_EQ(s, R"({"status":"ok"})");
43+
const auto ss = getResponse("/api/v0/users", boost::beast::http::verb::get);
44+
const auto expected = nlohmann::json::parse(json_response);
45+
const auto received = nlohmann::json::parse(json_response);
46+
EXPECT_EQ(expected.dump(), received.dump());
4047
});
4148
}

‎test/http_methods.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEST(HttpMethods, TestDiffentMethods) {
1212
expresscpp->Delete("/", [](auto /*req*/, auto res) { res->Send("delete"); });
1313
expresscpp->Patch("/", [](auto /*req*/, auto res) { res->Send("patch"); });
1414

15-
expresscpp->Listen(8080, []() {
15+
expresscpp->Listen(8081, []() {
1616
const auto s_get = getResponse("/", boost::beast::http::verb::get);
1717
const auto s_post = getResponse("/", boost::beast::http::verb::post);
1818
const auto s_delete = getResponse("/", boost::beast::http::verb::delete_);

‎test/routing_table.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ TEST(RoutingTable, TestBasicRouting) {
1111
expresscpp->Get("/c", [](auto /*req*/, auto res) { res->Send("get_c"); });
1212
expresscpp->Post("/d", [](auto /*req*/, auto res) { res->Send("post_d"); });
1313

14-
expresscpp->Listen(8080, [=]() {
14+
expresscpp->Listen(8081, [=]() {
1515
const auto a = getResponse("/a", boost::beast::http::verb::get);
1616
EXPECT_EQ(a, "get_a");
1717

@@ -38,13 +38,15 @@ TEST(RoutingTable, TestDefaultRouting) {
3838
res->Send(error);
3939
});
4040

41-
expresscpp->Listen(8080, [=]() {
41+
expresscpp->Listen(8081, [=]() {
4242
const auto a = getResponse("/a", boost::beast::http::verb::get);
4343
EXPECT_EQ(a, "get_a");
4444

4545
auto e = getResponse("/e", boost::beast::http::verb::post);
4646
EXPECT_EQ(e, error);
4747
e = getResponse("/e", boost::beast::http::verb::get);
4848
EXPECT_EQ(e, error);
49+
// TODO: do some expectations here
50+
expresscpp->Stack();
4951
});
5052
}

‎test/static_file_middleware.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(StaticFileMiddleware, ServeIndexHtml) {
3636
// ExpressJS: app.use(express.static('tmp'))
3737
expresscpp->Use(expresscpp->GetStaticFileProvider(path_to_index_html.parent_path()));
3838

39-
expresscpp->Listen(8080, [=]() {
39+
expresscpp->Listen(8081, [=]() {
4040
// should get the index.html file
4141
auto index_html_contect_response = getResponse("/", boost::beast::http::verb::get);
4242

‎test/test_utils.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ std::string getResponse(const std::string& path, boost::beast::http::verb verb)
2020

2121
try {
2222
auto const host = "localhost";
23-
auto const port = "8080";
23+
auto const port = "8081";
2424
// auto const target = "/";
2525
int version = 11;
2626

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL