You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
#include "webcc/rest_service_manager.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace webcc;
|
|
|
|
class TestRestService : public RestService {
|
|
public:
|
|
bool Handle(const std::string& http_method,
|
|
const std::vector<std::string>& url_sub_matches,
|
|
const webcc::UrlQuery& query,
|
|
const std::string& request_content,
|
|
std::string* response_content) override {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
TEST(RestServiceManager, URL_RegexBasic) {
|
|
RestServiceManager service_manager;
|
|
|
|
{
|
|
RestServicePtr service = std::make_shared<TestRestService>();
|
|
|
|
service_manager.AddService(service, "/instances/(\\d+)");
|
|
}
|
|
|
|
std::vector<std::string> sub_matches;
|
|
|
|
std::string url = "/instances/12345";
|
|
RestServicePtr service = service_manager.GetService(url, &sub_matches);
|
|
|
|
EXPECT_TRUE(!!service);
|
|
|
|
EXPECT_EQ(1, sub_matches.size());
|
|
EXPECT_EQ("12345", sub_matches[0]);
|
|
|
|
url = "/instances/abcde";
|
|
sub_matches.clear();
|
|
service = service_manager.GetService(url, &sub_matches);
|
|
|
|
EXPECT_FALSE(!!service);
|
|
}
|