Skip to content

Commit

Permalink
cov
Browse files Browse the repository at this point in the history
  • Loading branch information
John-LittleBearLabs committed Oct 8, 2024
1 parent bd1e9fd commit c2675c0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ function(setup_target_for_coverage_lcov)
${GENHTML_PATH}
${GENHTML_EXTRA_ARGS}
${Coverage_GENHTML_ARGS}
--rc genhtml_hi_limit=88
--rc genhtml_med_limit=74
--rc genhtml_hi_limit=89
--rc genhtml_med_limit=78
--prefix "${BASEDIR}"
-o ${Coverage_NAME}
${Coverage_NAME}.info
Expand Down
4 changes: 4 additions & 0 deletions library/include/multibase/algorithm.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

// LCOV_EXCL_START

#include <string>

namespace multibase {
Expand All @@ -26,3 +28,5 @@ class algorithm {
};

} // namespace multibase

// LCOV_EXCL_STOP
4 changes: 4 additions & 0 deletions library/include/multibase/basic_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#pragma once

// LCOV_EXCL_START

#include <multibase/algorithm.h>
#include <multibase/encoding.h>

Expand Down Expand Up @@ -320,3 +322,5 @@ struct traits<encoding::base_64> {
using base_64 = basic_algorithm<encoding::base_64>;

} // namespace multibase

// LCOV_EXCL_STOP
2 changes: 1 addition & 1 deletion library/src/ipfs_client/gw/dnslink_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool parse_results(ipfs::gw::RequestPtr req,
constexpr auto prefix = "dnslink="sv;
auto t = Source::Clock::now();
for (auto& result : results) {
if (starts_with(result, prefix)) {
if (result.starts_with(prefix)) {
Source src;
src.fetched_at = t;
src.load_duration = t - start;
Expand Down
17 changes: 17 additions & 0 deletions library/src/ipfs_client/ipld/dag_node_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <mock_api.h>

#include <ipfs_client/ipld/dag_json_node.h>
#include <ipfs_client/ipld/dnslink_name.h>

using T = ii::DagNode;

Expand All @@ -18,3 +19,19 @@ TEST_F(DagNodeTest,ConstructDagJson) {
auto d = dynamic_cast<ii::DagJsonNode*>(p.get());
ASSERT_TRUE(d);
}
TEST_F(DagNodeTest,DnsLinkIs) {
ii::DnsLinkName d{"/ipfs/baguqeaaeejugsiq"};
auto p = static_cast<T*>(&d);
ASSERT_TRUE(p);
auto down = p->as_dnslink();
EXPECT_TRUE(down);
EXPECT_TRUE(down == &d);
}
TEST_F(DagNodeTest,DagJsonIsNotOtherTHings) {
i::Cid cid{"baguqeaaeejugsiq"};
auto p = T::fromBytes(api, cid, "\"hi\"");
ASSERT_TRUE(p);
EXPECT_FALSE(p->as_dnslink());
EXPECT_FALSE(p->as_hamt());
EXPECT_FALSE(p->as_ipns());
}
4 changes: 2 additions & 2 deletions library/src/ipfs_client/ipld/directory_shard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ auto Self::resolve_internal(ipfs::ipld::DirShard::HashIter hash_b,
auto hash_chunk = hash_b == hash_e ? std::string{} : *hash_b;
auto needed_size = hash_chunk.size() + human_name.size();
for (auto& [name, link] : links_) {
if (!starts_with(name, hash_chunk)) {
if (!name.starts_with(hash_chunk)) {
continue;
}
if (name.size() == needed_size && ends_with(name, human_name)) {
if (name.size() == needed_size && name.ends_with(human_name)) {
return CallChild(parms, name);
}
auto node = parms.GetBlock(link.cid);
Expand Down
2 changes: 1 addition & 1 deletion library/src/ipfs_client/redirects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::uint16_t r::Directive::rewrite(std::string& path) const {
}
}
std::string r::Directive::error() const {
if (starts_with(to_, "ERROR: ")) {
if (to_.starts_with("ERROR: ")) {
return to_;
}
if (status_ < 200 || status_ > 451) {
Expand Down
13 changes: 0 additions & 13 deletions library/src/log_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,4 @@ static bool const is_logging_initialized = ::ipfs::log::IsInitialized();

#define L_VAR(X) LOG(INFO) << "VAR " << #X << "='" << (X) << '\'';

inline auto starts_with(std::string_view full_text, std::string_view prefix) -> bool {
if (prefix.size() > full_text.size()) {
return false;
}
return full_text.substr(0UL, prefix.size()) == prefix;
}
inline auto ends_with(std::string_view full_text, std::string_view suffix) -> bool {
if (suffix.size() > full_text.size()) {
return false;
}
return full_text.substr(full_text.size() - suffix.size()) == suffix;
}

#endif // IPFS_LOG_MACROS_H_

0 comments on commit c2675c0

Please sign in to comment.