3333
3434namespace mockserver {
3535
36+ namespace {
3637const auto kBaseUrl = " https://localhost:1080" ;
3738const auto kExpectationPath = " /mockserver/expectation" ;
3839const auto kStatusPath = " /mockserver/status" ;
3940const auto kResetPath = " /mockserver/reset" ;
41+ const auto kClearPath = " /mockserver/clear" ;
4042const auto kTimeout = std::chrono::seconds{10 };
43+ } // namespace
4144
4245class Client {
4346 public:
@@ -55,6 +58,9 @@ class Client {
5558
5659 void Reset ();
5760
61+ void RemoveMockResponse (const std::string& method_matcher,
62+ const std::string& path_matcher);
63+
5864 private:
5965 void CreateExpectation (const Expectation& expectation);
6066
@@ -127,8 +133,28 @@ inline Status::Ports Client::Ports() const {
127133inline void Client::Reset () {
128134 auto response = http_client_->CallApi (kResetPath , " PUT" , {}, {}, {}, nullptr ,
129135 " " , olp::client::CancellationContext{});
136+ }
137+
138+ inline void Client::RemoveMockResponse (const std::string& method_matcher,
139+ const std::string& path_matcher) {
140+ rapidjson::StringBuffer buffer;
141+ rapidjson::Writer<rapidjson::StringBuffer> writer (buffer);
142+
143+ writer.StartObject ();
144+ writer.Key (" method" );
145+ writer.String (method_matcher.c_str ());
146+ writer.Key (" path" );
147+ writer.String (path_matcher.c_str ());
148+ writer.EndObject ();
149+
150+ const auto data = std::string{buffer.GetString ()};
130151
131- return ;
152+ const auto request_body =
153+ std::make_shared<std::vector<unsigned char >>(data.begin (), data.end ());
154+
155+ auto response =
156+ http_client_->CallApi (kClearPath , " PUT" , {}, {}, {}, request_body, " " ,
157+ olp::client::CancellationContext{});
132158}
133159
134160inline void Client::CreateExpectation (const Expectation& expectation) {
@@ -139,8 +165,6 @@ inline void Client::CreateExpectation(const Expectation& expectation) {
139165 auto response =
140166 http_client_->CallApi (kExpectationPath , " PUT" , {}, {}, {}, request_body,
141167 " " , olp::client::CancellationContext{});
142-
143- return ;
144168}
145169
146170} // namespace mockserver
0 commit comments