Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a ut
Browse files Browse the repository at this point in the history
John-LittleBearLabs committed Jan 17, 2024
1 parent c3badfb commit 5c10781
Showing 6 changed files with 29 additions and 7 deletions.
9 changes: 5 additions & 4 deletions library/include/ipfs_client/gw/requestor.h
Original file line number Diff line number Diff line change
@@ -18,17 +18,18 @@ class GatewayRequest;
using RequestPtr = std::shared_ptr<GatewayRequest>;

class Requestor : public std::enable_shared_from_this<Requestor> {
protected:
Requestor() {}

friend class RequestorPool;
public:
enum class HandleOutcome : char {
NOT_HANDLED = 'N',
PENDING = 'P',
DONE = 'D',
PARALLEL = 'L',
MAYBE_LATER = 'M'
};

protected:
Requestor() {}

virtual HandleOutcome handle(RequestPtr) = 0;

void definitive_failure(RequestPtr) const;
3 changes: 3 additions & 0 deletions library/src/ipfs_client/gw/multi_gateway_requestor.cc
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@ std::string_view Self::name() const {
return "multi-gateway requestor";
}
auto Self::handle(RequestPtr r) -> HandleOutcome {
if (!r || !api_) {
return HandleOutcome::DONE;
}
if (!r->is_http()) {
LOG(INFO) << r->debug_string() << " is not an HTTP request.";
return HandleOutcome::NOT_HANDLED;
21 changes: 21 additions & 0 deletions library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "multi_gateway_requestor.h"

#include <mock_api.h>

#include <ipfs_client/gw/gateway_request.h>

namespace {
ig::RequestPtr block_req() {
auto rv = std::make_shared<ig::GatewayRequest>();
rv->type = ig::Type::Block;
rv->main_param =
"bafybeid4dzlxm6h4r6kfvx6jp6vj4nteplmbve224lx2s3lgjubyufsuo4";
return rv;
}
} // namespace

TEST(MultiGatewayRequestor, FailsWithoutApi) {
ig::MultiGatewayRequestor t;
auto o = t.handle(block_req());
EXPECT_TRUE(o == ig::Requestor::HandleOutcome::DONE);
}

This file was deleted.

Binary file not shown.

This file was deleted.

0 comments on commit 5c10781

Please sign in to comment.