From 016bbe8b730482768b69b21504f6942750e0050b Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Thu, 13 Dec 2018 10:47:54 +0000 Subject: use portal server for unit test --- .../src/tests/config_status/config_status_test.cpp | 41 ++++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/configutil/src/tests/config_status/config_status_test.cpp b/configutil/src/tests/config_status/config_status_test.cpp index 5d2ade442df..304d4518b41 100644 --- a/configutil/src/tests/config_status/config_status_test.cpp +++ b/configutil/src/tests/config_status/config_status_test.cpp @@ -1,49 +1,44 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include +#include #include -#include +#include #include #include #include using namespace config; +using vespalib::Portal; +using vespalib::NullCryptoEngine; -class HTTPStatus : private Fast_HTTPServer { +auto create_server() { return Portal::create(std::make_shared(), 0); } + +class HTTPStatus : public vespalib::Portal::GetHandler { private: + Portal::SP _server; std::string _reply; bool _fail; + Portal::Token::UP _root; - void onGetRequest(const string &, const string &, Fast_HTTPConnection &conn) override { + void get(Portal::GetRequest request) const override { if (_fail) { - conn.Output(conn.GetHTTPVersion().c_str()); - conn.Output(" 500 Error\r\n"); - conn.Output("Connection: close\r\n"); - conn.Output("\r\n"); + request.respond_with_error(500, "Error"); } else { - conn.Output(conn.GetHTTPVersion().c_str()); - conn.Output(" 200 OK\r\n"); - conn.Output("Content-Type: application/json\r\n\r\n"); - conn.Output(_reply.c_str()); + request.respond_with_content("application/json", _reply); } }; - public: HTTPStatus(std::string reply) - : Fast_HTTPServer(0), _reply(reply), _fail(false) - { - Start(); - }; + : _server(create_server()), _reply(reply), _fail(false), + _root(_server->bind("/", *this)) {} HTTPStatus(bool fail) - : Fast_HTTPServer(0), _reply(""), _fail(fail) - { - Start(); - }; + : _server(create_server()), _reply(""), _fail(fail), + _root(_server->bind("/", *this)) {} - int getListenPort() { return Fast_HTTPServer::getListenPort(); } + int getListenPort() { return _server->listen_port(); } ~HTTPStatus() { - Stop(); + _root.reset(); }; }; -- cgit v1.2.3