userver: userver/ugrpc/tests/service_fixtures.hpp Source File
Loading...
Searching...
No Matches
service_fixtures.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/tests/service_fixtures.hpp
4/// @brief gtest fixtures for testing ugrpc service implementations. Requires
5/// linking to `userver::grpc-utest`.
6
7#include <userver/utest/utest.hpp>
8#include <userver/utils/statistics/labels.hpp>
9#include <userver/utils/statistics/testing.hpp>
10
11#include <userver/ugrpc/tests/service.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace ugrpc::tests {
16
17/// @see @ref ugrpc::tests::ServiceBase
18// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
19class ServiceFixtureBase : protected ServiceBase, public ::testing::Test {
20protected:
21 /// @returns the statistics of the server and clients.
22 utils::statistics::Snapshot
23 GetStatistics(std::string prefix, std::vector<utils::statistics::Label> require_labels = {});
24};
25
26/// @see @ref ugrpc::tests::Service
27template <typename GrpcService>
28// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
29class ServiceFixture : protected Service<GrpcService>, public ::testing::Test {
30protected:
31 using Service<GrpcService>::Service;
32
33 /// @returns the statistics of the server and clients.
34 utils::statistics::Snapshot
35 GetStatistics(std::string prefix, std::vector<utils::statistics::Label> require_labels = {}) {
36 return utils::statistics::Snapshot{this->GetStatisticsStorage(), std::move(prefix), std::move(require_labels)};
37 }
38};
39
40} // namespace ugrpc::tests
41
42USERVER_NAMESPACE_END