nix-super/tests/unit/libfetchers/public-key.cc
HaeNoe 50cb14fcf9
Improve checked json casting (#10087)
This introduces new utility functions to get elements from JSON — in an ergonomic way and with nice error messages if the expected type does not match.

Co-authored-by: John Ericson <John.Ericson@Obsidian.Systems>
2024-04-03 18:04:00 +00:00

18 lines
559 B
C++

#include <gtest/gtest.h>
#include "fetchers.hh"
#include "json-utils.hh"
namespace nix {
TEST(PublicKey, jsonSerialization) {
auto json = nlohmann::json(fetchers::PublicKey { .key = "ABCDE" });
ASSERT_EQ(json, R"({ "key": "ABCDE", "type": "ssh-ed25519" })"_json);
}
TEST(PublicKey, jsonDeserialization) {
auto pubKeyJson = R"({ "key": "ABCDE", "type": "ssh-ed25519" })"_json;
fetchers::PublicKey pubKey = pubKeyJson;
ASSERT_EQ(pubKey.key, "ABCDE");
ASSERT_EQ(pubKey.type, "ssh-ed25519");
}
}