unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-12-21 17:33:35 -06:00
parent 1511603b6a
commit ca7257d7f7
3 changed files with 87 additions and 0 deletions

View File

@ -629,6 +629,26 @@ template <> struct adl_serializer<std::atomic<repertory::download_type>> {
value.store(repertory::download_type_from_string(data.get<std::string>())); value.store(repertory::download_type_from_string(data.get<std::string>()));
} }
}; };
template <> struct adl_serializer<repertory::database_type> {
static void to_json(json &data, const repertory::database_type &value) {
data = repertory::database_type_to_string(value);
}
static void from_json(const json &data, repertory::database_type &value) {
value = repertory::database_type_from_string(data.get<std::string>());
}
};
template <> struct adl_serializer<repertory::download_type> {
static void to_json(json &data, const repertory::download_type &value) {
data = repertory::download_type_to_string(value);
}
static void from_json(const json &data, repertory::download_type &value) {
value = repertory::download_type_from_string(data.get<std::string>());
}
};
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ #endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_

View File

@ -28,6 +28,11 @@ TEST(atomic, atomic_primitive) {
atomic<std::uint16_t> value; atomic<std::uint16_t> value;
value = 5U; value = 5U;
EXPECT_EQ(5U, static_cast<std::uint16_t>(value)); EXPECT_EQ(5U, static_cast<std::uint16_t>(value));
EXPECT_EQ(5U, value.load());
value.store(6U);
EXPECT_EQ(6U, static_cast<std::uint16_t>(value));
EXPECT_EQ(6U, value.load());
} }
TEST(atomic, atomic_primitive_equality) { TEST(atomic, atomic_primitive_equality) {

View File

@ -183,4 +183,66 @@ TEST(json_serialize, can_handle_sia_config) {
EXPECT_STREQ(cfg2.bucket.c_str(), cfg.bucket.c_str()); EXPECT_STREQ(cfg2.bucket.c_str(), cfg.bucket.c_str());
} }
} }
TEST(json_serialize, can_handle_atomic) {
atomic<sia_config> cfg({
"bucket",
});
json data(cfg);
EXPECT_STREQ("bucket", data.at(JSON_BUCKET).get<std::string>().c_str());
{
auto cfg2 = data.get<atomic<sia_config>>();
EXPECT_STREQ(cfg2.load().bucket.c_str(), cfg.load().bucket.c_str());
}
}
TEST(json_serialize, can_handle_database_type) {
json data(database_type::rocksdb);
EXPECT_EQ(database_type::rocksdb, data.get<database_type>());
EXPECT_STREQ("rocksdb", data.get<std::string>().c_str());
data = database_type::sqlite;
EXPECT_EQ(database_type::sqlite, data.get<database_type>());
EXPECT_STREQ("sqlite", data.get<std::string>().c_str());
}
TEST(json_serialize, can_handle_download_type) {
json data(download_type::direct);
EXPECT_EQ(download_type::direct, data.get<download_type>());
EXPECT_STREQ("direct", data.get<std::string>().c_str());
data = download_type::fallback;
EXPECT_EQ(download_type::fallback, data.get<download_type>());
EXPECT_STREQ("fallback", data.get<std::string>().c_str());
data = download_type::ring_buffer;
EXPECT_EQ(download_type::ring_buffer, data.get<download_type>());
EXPECT_STREQ("ring_buffer", data.get<std::string>().c_str());
}
TEST(json_serialize, can_handle_atomic_database_type) {
json data(atomic<database_type>{database_type::rocksdb});
EXPECT_EQ(database_type::rocksdb, data.get<atomic<database_type>>());
EXPECT_STREQ("rocksdb", data.get<std::string>().c_str());
data = atomic<database_type>(database_type::sqlite);
EXPECT_EQ(database_type::sqlite, data.get<atomic<database_type>>());
EXPECT_STREQ("sqlite", data.get<std::string>().c_str());
}
TEST(json_serialize, can_handle_atomic_download_type) {
json data(atomic<download_type>{download_type::direct});
EXPECT_EQ(download_type::direct, data.get<atomic<download_type>>());
EXPECT_STREQ("direct", data.get<std::string>().c_str());
data = atomic<download_type>{download_type::fallback};
EXPECT_EQ(download_type::fallback, data.get<download_type>());
EXPECT_STREQ("fallback", data.get<std::string>().c_str());
data = atomic<download_type>{download_type::ring_buffer};
EXPECT_EQ(download_type::ring_buffer, data.get<atomic<download_type>>());
EXPECT_STREQ("ring_buffer", data.get<std::string>().c_str());
}
} // namespace repertory } // namespace repertory