From 5c10781e5182b8dd99e4aaf33d952cf5b8adb763 Mon Sep 17 00:00:00 2001 From: John Turpish Date: Wed, 17 Jan 2024 10:25:37 -0500 Subject: [PATCH] Add a ut --- library/include/ipfs_client/gw/requestor.h | 9 ++++---- .../ipfs_client/gw/multi_gateway_requestor.cc | 3 +++ .../gw/multi_gateway_requestor_unittest.cc | 21 ++++++++++++++++++ ...HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 | 2 -- ...pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf | Bin 649 -> 0 bytes ...lugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum | 1 - 6 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc delete mode 100644 test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 delete mode 100644 test_data/blocks/QmU9pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf delete mode 100644 test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum diff --git a/library/include/ipfs_client/gw/requestor.h b/library/include/ipfs_client/gw/requestor.h index 634c3673..0aba88b5 100644 --- a/library/include/ipfs_client/gw/requestor.h +++ b/library/include/ipfs_client/gw/requestor.h @@ -18,10 +18,7 @@ class GatewayRequest; using RequestPtr = std::shared_ptr; class Requestor : public std::enable_shared_from_this { - protected: - Requestor() {} - - friend class RequestorPool; + public: enum class HandleOutcome : char { NOT_HANDLED = 'N', PENDING = 'P', @@ -29,6 +26,10 @@ class Requestor : public std::enable_shared_from_this { PARALLEL = 'L', MAYBE_LATER = 'M' }; + + protected: + Requestor() {} + virtual HandleOutcome handle(RequestPtr) = 0; void definitive_failure(RequestPtr) const; diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor.cc b/library/src/ipfs_client/gw/multi_gateway_requestor.cc index e1de2464..6d3c12a9 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor.cc +++ b/library/src/ipfs_client/gw/multi_gateway_requestor.cc @@ -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; diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc b/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc new file mode 100644 index 00000000..c57140db --- /dev/null +++ b/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc @@ -0,0 +1,21 @@ +#include "multi_gateway_requestor.h" + +#include + +#include + +namespace { +ig::RequestPtr block_req() { + auto rv = std::make_shared(); + 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); +} \ No newline at end of file diff --git a/test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 b/test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 deleted file mode 100644 index 7eb16a2d..00000000 --- a/test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 +++ /dev/null @@ -1,2 +0,0 @@ - -Lu0 Lu1 Lu2 Lu3 Lu4 Lu5 Lu6 Lu7 Lu8 Lu9 Lv0 Lv1 Lv2 Lv3 Lv4 Lv5 Lv6 Lv7 Lv8 Lv9 Lw0 Lw1 Lw2 Lw3 Lw4 Lw5 Lw6 Lw7 Lw8 Lw9 Lx0 Lx1 Lx2 Lx3 Lx4 Lx5  \ No newline at end of file diff --git a/test_data/blocks/QmU9pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf b/test_data/blocks/QmU9pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf deleted file mode 100644 index a2fa4e0658aebc4f211bffeab41fc790ed249fd7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 649 zcmWgAI#J+}~p#B4?(uu{ga zs%mRGPOfs&4>`p9Vf~GLPT3RUJzNA1wfUE4IKR7wq*S=MG(GUR(%EGq+~-$JvtqW3 zKd{Y1^4i<#xy$xhdkcdfOi-_@OY9gesryr1ENq||VE5W7|Ht&{JIzHoHi z{oBeOpeDv&xcvB93w7rWEkEBQDNSwPHSurR1s$G#r(-V~^$dLLKKL0mzB67qLGn#$va7#Rcx}{NTV38uKlXlnRHnO|Omr^k$F9 zI!W^lMeCDJ_J7JEQd5tz&w^)HOG}tv_1pcs%e`=lz7Fv|i-uVlH*> zsjW-J+I1UWO-eX>LuXwW*BOSH$|~Jykaw-p+kd#s^ed S!KKH+ByoUWVFDvjr~m+uO80sI diff --git a/test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum b/test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum deleted file mode 100644 index 4fc3fe1c..00000000 --- a/test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum +++ /dev/null @@ -1 +0,0 @@ -G \ No newline at end of file