Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] clang-tidy auto fixes #1046

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/clang_format/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ runs:
shell: bash

- name: Run formatter
continue-on-error: true
id: run_formatter
run: |
./.githooks/pre-commit
shell: bash
Expand All @@ -27,3 +29,8 @@ runs:
shell: bash
run: |
git diff --color --exit-code | tee "clang-format.patch"

- name: Fail job
if: ${{ steps.run_formatter.outcome != 'success' }}
shell: bash
run: exit 1
14 changes: 7 additions & 7 deletions unittests/data/cassandra/impl/FakesAndMocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct FakeResultOrError {
return err;
}

FakeResult
value() const
static FakeResult
value()
{
return FakeResult{};
}
Expand All @@ -65,8 +65,8 @@ struct FakeFuture {
return data;
}

FakeMaybeError
await() const
static FakeMaybeError
await()
{
return {};
}
Expand Down Expand Up @@ -103,14 +103,14 @@ struct MockHandle {
struct FakeRetryPolicy {
FakeRetryPolicy(boost::asio::io_context&){}; // required by concept

std::chrono::milliseconds
static std::chrono::milliseconds
calculateDelay(uint32_t /* attempt */)
{
return std::chrono::milliseconds{1};
}

bool
shouldRetry(CassandraError) const
static bool
shouldRetry(CassandraError)
{
return false;
}
Expand Down
20 changes: 10 additions & 10 deletions unittests/rpc/handlers/impl/FakesAndMocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class HandlerFake {
using Output = TestOutput;
using Result = rpc::HandlerReturnType<Output>;

rpc::RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion) const
static rpc::RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
using namespace rpc::validation;

Expand All @@ -83,8 +83,8 @@ class HandlerFake {
return rpcSpec;
}

Result
process(Input input, [[maybe_unused]] rpc::Context const& ctx) const
static Result
process(Input input, [[maybe_unused]] rpc::Context const& ctx)
{
return Output{input.hello + '_' + std::to_string(input.limit.value_or(0))};
}
Expand All @@ -95,8 +95,8 @@ class NoInputHandlerFake {
using Output = TestOutput;
using Result = rpc::HandlerReturnType<Output>;

Result
process([[maybe_unused]] rpc::Context const& ctx) const
static Result
process([[maybe_unused]] rpc::Context const& ctx)
{
return Output{"test"};
}
Expand All @@ -109,8 +109,8 @@ class FailingHandlerFake {
using Output = TestOutput;
using Result = rpc::HandlerReturnType<Output>;

rpc::RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion) const
static rpc::RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
using namespace rpc::validation;

Expand All @@ -122,8 +122,8 @@ class FailingHandlerFake {
return rpcSpec;
}

Result
process([[maybe_unused]] Input input, [[maybe_unused]] rpc::Context const& ctx) const
static Result
process([[maybe_unused]] Input input, [[maybe_unused]] rpc::Context const& ctx)
{
// always fail
return rpc::Error{rpc::Status{"Very custom error"}};
Expand Down
2 changes: 1 addition & 1 deletion unittests/util/FakeAmendmentBlockAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct FakeAmendmentBlockAction {
std::reference_wrapper<std::size_t> callCount;

void
operator()()
operator()() const
{
++(callCount.get());
}
Expand Down
15 changes: 8 additions & 7 deletions unittests/util/FakeFetchResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <cstddef>
#include <string>
#include <utility>
#include <vector>

class FakeBook {
Expand Down Expand Up @@ -135,7 +136,7 @@ class FakeTransactionsList {

public:
std::size_t
transactions_size()
transactions_size() const
{
return size_;
}
Expand All @@ -146,7 +147,7 @@ class FakeObjectsList {

public:
std::size_t
objects_size()
objects_size() const
{
return size_;
}
Expand All @@ -165,7 +166,7 @@ struct FakeFetchResponse {
}

FakeFetchResponse(std::string blob, uint32_t id = 0, bool objectNeighborsIncluded = false)
: id{id}, objectNeighborsIncluded{objectNeighborsIncluded}, ledgerHeader{blob}
: id{id}, objectNeighborsIncluded{objectNeighborsIncluded}, ledgerHeader{std::move(blob)}
{
}

Expand All @@ -175,14 +176,14 @@ struct FakeFetchResponse {
return other.id == id;
}

FakeTransactionsList
transactions_list() const
static FakeTransactionsList
transactions_list()
{
return {};
}

FakeObjectsList
ledger_objects() const
static FakeObjectsList
ledger_objects()
{
return {};
}
Expand Down
19 changes: 17 additions & 2 deletions unittests/util/Fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,32 @@

#pragma once

#include "data/BackendInterface.h"
#include "util/MockBackend.h"
#include "util/MockCounters.h"
#include "util/MockETLService.h"
#include "util/MockLoadBalancer.h"
#include "util/MockSubscriptionManager.h"
#include "util/log/Logger.h"

#include <boost/asio.hpp>
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/log/core/core.hpp>
#include <boost/log/expressions/predicates/channel_severity_filter.hpp>
#include <boost/log/keywords/format.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/formatter_parser.hpp>
#include <gtest/gtest.h>

#include <memory>
#include <mutex>
#include <optional>
#include <ostream>
#include <sstream>
#include <string>
#include <thread>

/**
Expand Down Expand Up @@ -181,7 +196,7 @@ struct MockBackendTest : virtual public NoLoggerFixture {
SetUp() override
{
NoLoggerFixture::SetUp();
util::Config cfg;
util::Config const cfg;
mockBackendPtr = std::make_shared<MockBackend>(cfg);
}
void
Expand Down
4 changes: 1 addition & 3 deletions unittests/util/MockSubscriptionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
struct MockSubscriptionManager {
public:
using session_ptr = std::shared_ptr<web::ConnectionBase>;
MockSubscriptionManager()
{
}
MockSubscriptionManager() = default;

MOCK_METHOD(boost::json::object, subLedger, (boost::asio::yield_context, session_ptr), ());

Expand Down
8 changes: 8 additions & 0 deletions unittests/util/MockWsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@

#pragma once

#include "util/Taggable.h"
#include "web/interface/ConnectionBase.h"

#include <boost/beast/http/status.hpp>

#include <memory>
#include <string>

struct MockSession : public web::ConnectionBase {
std::string message;
void
Expand All @@ -30,6 +36,7 @@ struct MockSession : public web::ConnectionBase {
}

void
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
send(std::string&& msg, boost::beast::http::status = boost::beast::http::status::ok) override
{
message += msg;
Expand All @@ -49,6 +56,7 @@ struct MockDeadSession : public web::ConnectionBase {
}

void
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
send(std::string&&, boost::beast::http::status = boost::beast::http::status::ok) override
{
}
Expand Down
38 changes: 31 additions & 7 deletions unittests/util/TestHttpSyncClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,36 @@

#pragma once

#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/ssl/verify_mode.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/stream_traits.hpp>
#include <boost/beast/core/tcp_stream.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/ssl.hpp>

#include <boost/beast/http/field.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/beast/http/verb.hpp>
#include <boost/beast/ssl/ssl_stream.hpp>
#include <boost/beast/version.hpp>
#include <boost/beast/websocket/rfc6455.hpp>
#include <boost/beast/websocket/stream.hpp>
#include <boost/beast/websocket/stream_base.hpp>
#include <openssl/err.h>
#include <openssl/tls1.h>

#include <optional>
#include <string>
#include <utility>
#include <vector>

namespace http = boost::beast::http;
namespace net = boost::asio;
Expand Down Expand Up @@ -126,8 +150,8 @@ class WebSocketSyncClient {
ws_.set_option(boost::beast::websocket::stream_base::decorator([additionalHeaders = std::move(additionalHeaders
)](boost::beast::websocket::request_type& req) {
req.set(http::field::user_agent, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-client-coro");
for (auto& header : additionalHeaders) {
req.set(header.name, std::move(header.value));
for (auto const& header : additionalHeaders) {
req.set(header.name, header.value);
}
}));

Expand Down Expand Up @@ -176,7 +200,7 @@ struct HttpsSyncClient {
if (!SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
#pragma GCC diagnostic pop
{
boost::beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
boost::beast::error_code const ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
throw boost::beast::system_error{ec};
}

Expand Down