FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
expresscpp/test/routing.cpp at master · hpsware/expresscpp · GitHub
hpsware
/
expresscpp
Public
forked from
expresscpp/expresscpp
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
expresscpp
/
test
/
routing.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (36 loc) · 1.67 KB
Breadcrumbs
expresscpp
/
test
/
routing.cpp
Copy path
File metadata and controls
42 lines (36 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
expresscpp/console.hpp
"
#
include
"
expresscpp/expresscpp.hpp
"
#
include
"
expresscpp/fetch.hpp
"
#
include
"
gtest/gtest.h
"
using
namespace
expresscpp
;
constexpr
uint16_t
port =
8081u
;
TEST
(RoutingTests, ChainRouting) {
ExpressCpp app;
app.
Use
(
"
/a
"
)
.
Get
([](
auto
/*
req
*/
,
auto
res,
auto
) { res->
Send
(
"
get request a
"
); })
.
Post
([](
auto
/*
req
*/
,
auto
res,
auto
) { res->
Send
(
"
post request a
"
); })
.
Put
([](
auto
/*
req
*/
,
auto
res,
auto
) { res->
Send
(
"
put request a
"
); });
app.
Use
(
"
/b
"
)
.
Get
([](
auto
/*
req
*/
,
auto
res,
auto
) { res->
Send
(
"
get request b
"
); })
.
Post
([](
auto
/*
req
*/
,
auto
res,
auto
) { res->
Send
(
"
post request b
"
); })
.
Put
([](
auto
/*
req
*/
,
auto
res,
auto
) { res->
Send
(
"
put request b
"
); });
app.
Listen
(port, [](
auto
ec) {
{
EXPECT_FALSE
(ec);
const
auto
get_response =
fetch
(
fmt::format
(
"
localhost:{}/a
"
, port), { HttpMethod::Get});
const
auto
post_response =
fetch
(
fmt::format
(
"
localhost:{}/a
"
, port), { HttpMethod::Post});
const
auto
put_response =
fetch
(
fmt::format
(
"
localhost:{}/a
"
, port), { HttpMethod::Put});
EXPECT_EQ
(get_response,
"
get request a
"
);
EXPECT_EQ
(post_response,
"
post request a
"
);
EXPECT_EQ
(put_response,
"
put request a
"
);
}
{
const
auto
get_response =
fetch
(
fmt::format
(
"
localhost:{}/b
"
, port), { HttpMethod::Get});
const
auto
post_response =
fetch
(
fmt::format
(
"
localhost:{}/b
"
, port), { HttpMethod::Post});
const
auto
put_response =
fetch
(
fmt::format
(
"
localhost:{}/b
"
, port), { HttpMethod::Put});
EXPECT_EQ
(get_response,
"
get request b
"
);
EXPECT_EQ
(post_response,
"
post request b
"
);
EXPECT_EQ
(put_response,
"
put request b
"
);
}
});
}
Back
|
FazBrowse Home
|
New Git URL