@@ -10,6 +10,7 @@ namespace onnxruntime {
10
10
namespace server {
11
11
namespace test {
12
12
13
+ static const std::string predict_regex = R"( /(?:v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict)))" ;
13
14
using test_data = std::tuple<http::verb, std::string, std::string, std::string, std::string, http::status>;
14
15
15
16
void do_something (const std::string& name, const std::string& version,
@@ -20,7 +21,6 @@ void do_something(const std::string& name, const std::string& version,
20
21
void run_route (const std::string& pattern, http::verb method, const std::vector<test_data>& data, bool does_validate_data);
21
22
22
23
TEST (HttpRouteTests, RegisterTest) {
23
- auto predict_regex = R"( /v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))" ;
24
24
Routes routes;
25
25
EXPECT_TRUE (routes.RegisterController (http::verb::post, predict_regex, do_something));
26
26
@@ -29,20 +29,22 @@ TEST(HttpRouteTests, RegisterTest) {
29
29
}
30
30
31
31
TEST (HttpRouteTests, PostRouteTest) {
32
- auto predict_regex = R"( /v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))" ;
33
32
34
33
std::vector<test_data> actions{
35
34
std::make_tuple (http::verb::post, " /v1/models/abc/versions/23:predict" , " abc" , " 23" , " predict" , http::status::ok),
36
35
std::make_tuple (http::verb::post, " /v1/models/abc:predict" , " abc" , " " , " predict" , http::status::ok),
37
36
std::make_tuple (http::verb::post, " /v1/models/models/versions/45:predict" , " models" , " 45" , " predict" , http::status::ok),
38
37
std::make_tuple (http::verb::post, " /v1/models/??$$%%@@$^^/versions/45:predict" , " ??$$%%@@$^^" , " 45" , " predict" , http::status::ok),
39
- std::make_tuple (http::verb::post, " /v1/models/versions/versions/45:predict" , " versions" , " 45" , " predict" , http::status::ok)};
38
+ std::make_tuple (http::verb::post, " /v1/models/versions/versions/45:predict" , " versions" , " 45" , " predict" , http::status::ok),
39
+ std::make_tuple (http::verb::post, " /v1/models/versions:predict" , " versions" , " " , " predict" , http::status::ok),
40
+ std::make_tuple (http::verb::post, " /v1/models/default:predict" , " default" , " " , " predict" , http::status::ok)
41
+ };
42
+
40
43
41
44
run_route (predict_regex, http::verb::post, actions, true );
42
45
}
43
46
44
47
TEST (HttpRouteTests, PostRouteInvalidURLTest) {
45
- auto predict_regex = R"( /v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))" ;
46
48
47
49
std::vector<test_data> actions{
48
50
std::make_tuple (http::verb::post, " " , " " , " " , " " , http::status::not_found),
@@ -56,27 +58,35 @@ TEST(HttpRouteTests, PostRouteInvalidURLTest) {
56
58
std::make_tuple (http::verb::post, " /models/abc/versions/2:predict" , " " , " " , " " , http::status::not_found),
57
59
std::make_tuple (http::verb::post, " /v1/models/versions/2:predict" , " " , " " , " " , http::status::not_found),
58
60
std::make_tuple (http::verb::post, " /v1/models/foo/versions/:predict" , " " , " " , " " , http::status::not_found),
59
- std::make_tuple (http::verb::post, " /v1/models/foo/versions:predict" , " " , " " , " " , http::status::not_found),
60
61
std::make_tuple (http::verb::post, " v1/models/foo/versions/12:predict" , " " , " " , " " , http::status::not_found),
61
- std::make_tuple (http::verb::post, " /v1/models/abc/versions/23:foo" , " " , " " , " " , http::status::not_found)};
62
+ std::make_tuple (http::verb::post, " /v1/models/abc/versions/23:foo" , " " , " " , " " , http::status::not_found)
63
+ };
62
64
63
65
run_route (predict_regex, http::verb::post, actions, false );
64
66
}
65
67
66
68
// These tests are because we currently only support POST and GET
67
69
// Some HTTP methods should be removed from test data if we support more (e.g. PUT)
68
70
TEST (HttpRouteTests, PostRouteInvalidMethodTest) {
69
- auto predict_regex = R"( /v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))" ;
70
71
71
72
std::vector<test_data> actions{
72
73
std::make_tuple (http::verb::get, " /v1/models/abc/versions/23:predict" , " abc" , " 23" , " predict" , http::status::method_not_allowed),
73
74
std::make_tuple (http::verb::put, " /v1/models" , " " , " " , " " , http::status::method_not_allowed),
74
75
std::make_tuple (http::verb::delete_, " /v1/models" , " " , " " , " " , http::status::method_not_allowed),
75
- std::make_tuple (http::verb::head, " /v1/models" , " " , " " , " " , http::status::method_not_allowed)};
76
+ std::make_tuple (http::verb::head, " /v1/models" , " " , " " , " " , http::status::method_not_allowed)
77
+ };
76
78
77
79
run_route (predict_regex, http::verb::post, actions, false );
78
80
}
79
81
82
+ TEST (HttpRouteTests, PostRouteSpecialMethodTest){
83
+ std::vector<test_data> actions{
84
+ std::make_tuple (http::verb::post, " /score" , " " , " " , " " , http::status::ok)
85
+ };
86
+
87
+ run_route (R"( /score()()())" , http::verb::post, actions, true );
88
+ }
89
+
80
90
void run_route (const std::string& pattern, http::verb method, const std::vector<test_data>& data, bool does_validate_data) {
81
91
Routes routes;
82
92
EXPECT_TRUE (routes.RegisterController (method, pattern, do_something));
@@ -95,11 +105,11 @@ void run_route(const std::string& pattern, http::verb method, const std::vector<
95
105
http::status expected_status;
96
106
97
107
std::tie (test_method, url_string, expected_name, expected_version, expected_action, expected_status) = i;
98
- EXPECT_EQ (expected_status, routes.ParseUrl (test_method, url_string, name, version, action, fn));
108
+ EXPECT_EQ (expected_status, routes.ParseUrl (test_method, url_string, name, version, action, fn)) << " On route " << url_string ;
99
109
if (does_validate_data) {
100
- EXPECT_EQ (name, expected_name);
101
- EXPECT_EQ (version, expected_version);
102
- EXPECT_EQ (action, expected_action);
110
+ EXPECT_EQ (name, expected_name) << " On route " << url_string ;
111
+ EXPECT_EQ (version, expected_version) << " On route " << url_string ;
112
+ EXPECT_EQ (action, expected_action) << " On route " << url_string ;
103
113
}
104
114
}
105
115
}
0 commit comments