Newer
Older
#include <vereign/service/gen/passport_service.hh>
#include <vereign/core/scope_guard.hh>
#include <vereign/client_library/passport_types.gen.pb.h>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <util/env.hh>
#include <util/protobuf.hh>
#include "catch.hpp"
#include <boost/asio/io_context.hpp>
#include <boost/asio/ssl/context.hpp>
#include <fmt/core.h>
TEST_CASE("PassportService::ListPassports", "[vereign/service/gen][.integration]") {
namespace asio = boost::asio;
namespace beast = boost::beast;
asio::io_context ioc;
auto work_guard = boost::asio::make_work_guard(ioc);
asio::ssl::context ctx(asio::ssl::context::tlsv12_client);
auto publicKey = vereign::test::RequireEnv("TEST_VEREIGN_PUB_KEY");
auto host = vereign::test::RequireEnv("TEST_VEREIGN_API_HOST");
auto port = vereign::test::GetEnv("TEST_VEREIGN_API_PORT", "https");
// Verify the remote server's certificate
// ctx.set_verify_mode(ssl::verify_peer);
vereign::restapi::Client client{ioc, ctx, host, port};
vereign::restapi::ClientSession client_session{client, publicKey};
vereign::service::gen::PassportService service{client_session};
std::thread ioc_thread([&ioc]{
ioc.run();
});
auto on_exit = vereign::core::MakeScopeGuard(
[&client_session, &ioc_thread, &work_guard] {
client_session.Close();
work_guard.reset();
ioc_thread.join();
}
);
for (int i = 0; i < 2; i++) {
auto req = std::make_unique<vereign::client_library::ListPassportsForm>();
auto resp = std::make_unique<vereign::client_library::ListPassportsFormResponse>();
auto list_result = service.ListPassports(req.get(), resp.get());
auto result = list_result.get();
// std::cout << vereign::test::ProtobufToJson(*result.Response) << std::endl;
auto& list = result.Response;
REQUIRE(list->error() == "");
CHECK(list->status() == "OK");
CHECK(list->code() == "200");
CHECK(list->data().size() > 0);
for (auto& passport : list->data()) {
CHECK(passport.uuid().size() == 36);
}
}
}