1#ifndef IPFS_MOCK_API_H_
2#define IPFS_MOCK_API_H_
4#include <gtest/gtest.h>
6#include <ipfs_client/client.h>
7#include <ipfs_client/json_cbor_adapter.h>
9#include "mock_http_provider.h"
10#include "mock_gw_cfg.h"
11#include "mock_sig_vtor.h"
20namespace ii = i::ipld;
21using RT = ig::GatewayRequestType;
23using namespace std::literals;
26struct MockDnsTxt :
public i::ctx::DnsTxtLookup {
27 struct DnsInvocation {
29 std::vector<std::string> txt_records;
32 std::vector<DnsInvocation>
mutable expected_dns;
33 void SendDnsTextRequest(std::string host,
34 DnsTextResultsCallback rcb,
35 DnsTextCompleteCallback ccb) {
36 EXPECT_GE(expected_dns.size(), 1U);
37 auto& e = expected_dns.at(0);
38 EXPECT_EQ(e.host, host);
40 expected_dns.erase(expected_dns.begin());
49 auto dns = std::make_unique<MockDnsTxt>();
52 auto g = std::make_unique<MockGwCfg>();
55 auto h = std::make_unique<MockHttpProvider>();
58 with(i::crypto::SigningKeyType::RSA, std::make_unique<MockSigVtor>());
59 with(i::crypto::SigningKeyType::Ed25519, std::make_unique<MockSigVtor>());
61 ~MockApi() noexcept
override {}
62 std::vector<i::HttpRequestDescription>
mutable http_requests_sent;
63 std::vector<ic::HttpApi::OnComplete>
mutable cbs;
64 std::string MimeType(std::string extension,
65 std::string_view content,
66 std::string
const& url)
const {
69 std::string UnescapeUrlComponent(std::string_view url_comp)
const {
72 bool VerifyKeySignature(SigningKeyType,
79 void Discover(std::function<
void(std::vector<std::string>)> cb) {}
80#if HAS_JSON_CBOR_ADAPTER
81 std::unique_ptr<ipfs::DagCborValue> ParseCbor(
ByteView bv)
const {
82 return std::make_unique<ipfs::JsonCborAdapter>(nlohmann::json::from_cbor(
83 bv,
false,
true, nlohmann::detail::cbor_tag_handler_t::store));
85 std::unique_ptr<ipfs::DagJsonValue> ParseJson(std::string_view jstr)
const {
86 return std::make_unique<ipfs::JsonCborAdapter>(nlohmann::json::parse(jstr));
89 std::unique_ptr<ipfs::DagCborValue> ParseCbor(
ByteView bv)
const {
92 std::unique_ptr<ipfs::DagJsonValue> ParseJson(std::string_view)
const {
Interface that provides functionality from whatever environment you're using this library in.
Definition client.h:42
Just an observing (non-owning) pointer.
Definition raw_ptr.h:31