Skip to content

Commit 9e7e810

Browse files
author
Sebastiano Merlino
committed
Added test case with double endpoint
1 parent 0629546 commit 9e7e810

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/basic.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ class only_render_resource : public http_resource<only_render_resource>
113113
}
114114
};
115115

116+
class ok_resource : public http_resource<ok_resource>
117+
{
118+
public:
119+
void render_GET(const http_request& req, http_response** res)
120+
{
121+
*res = new http_string_response("OK", 200, "text/plain");
122+
}
123+
};
124+
125+
class nok_resource : public http_resource<nok_resource>
126+
{
127+
public:
128+
void render_GET(const http_request& req, http_response** res)
129+
{
130+
*res = new http_string_response("NOK", 200, "text/plain");
131+
}
132+
};
133+
116134
LT_BEGIN_SUITE(basic_suite)
117135

118136
webserver* ws;
@@ -130,6 +148,44 @@ LT_BEGIN_SUITE(basic_suite)
130148
}
131149
LT_END_SUITE(basic_suite)
132150

151+
LT_BEGIN_AUTO_TEST(basic_suite, two_endpoints)
152+
153+
ok_resource* ok = new ok_resource();
154+
ws->register_resource("OK", ok);
155+
nok_resource* nok = new nok_resource();
156+
ws->register_resource("NOK", nok);
157+
158+
curl_global_init(CURL_GLOBAL_ALL);
159+
std::string s;
160+
{
161+
CURL *curl = curl_easy_init();
162+
CURLcode res;
163+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/OK");
164+
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
165+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
166+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
167+
res = curl_easy_perform(curl);
168+
LT_ASSERT_EQ(res, 0);
169+
LT_CHECK_EQ(s, "OK");
170+
curl_easy_cleanup(curl);
171+
}
172+
173+
std::string t;
174+
{
175+
CURL *curl = curl_easy_init();
176+
CURLcode res;
177+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/NOK");
178+
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
179+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
180+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &t);
181+
res = curl_easy_perform(curl);
182+
LT_ASSERT_EQ(res, 0);
183+
LT_CHECK_EQ(t, "NOK");
184+
curl_easy_cleanup(curl);
185+
}
186+
187+
LT_END_AUTO_TEST(two_endpoints)
188+
133189
LT_BEGIN_AUTO_TEST(basic_suite, read_body)
134190
simple_resource* resource = new simple_resource();
135191
ws->register_resource("base", resource);

0 commit comments

Comments
 (0)