mirror of
https://github.com/NixOS/nix.git
synced 2025-12-03 23:51:00 +01:00
For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
54 lines
2.2 KiB
C++
54 lines
2.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include "nix/fetchers/fetchers.hh"
|
|
#include "nix/util/json-utils.hh"
|
|
#include <nlohmann/json.hpp>
|
|
#include "nix/util/tests/characterization.hh"
|
|
|
|
namespace nix {
|
|
|
|
using nlohmann::json;
|
|
|
|
class PublicKeyTest : public CharacterizationTest
|
|
{
|
|
std::filesystem::path unitTestData = getUnitTestData() / "public-key";
|
|
|
|
public:
|
|
std::filesystem::path goldenMaster(std::string_view testStem) const override {
|
|
return unitTestData / testStem;
|
|
}
|
|
};
|
|
|
|
#define TEST_JSON(FIXTURE, NAME, VAL) \
|
|
TEST_F(FIXTURE, PublicKey_ ## NAME ## _from_json) { \
|
|
readTest(#NAME ".json", [&](const auto & encoded_) { \
|
|
fetchers::PublicKey expected { VAL }; \
|
|
fetchers::PublicKey got = nlohmann::json::parse(encoded_); \
|
|
ASSERT_EQ(got, expected); \
|
|
}); \
|
|
} \
|
|
\
|
|
TEST_F(FIXTURE, PublicKey_ ## NAME ## _to_json) { \
|
|
writeTest(#NAME ".json", [&]() -> json { \
|
|
return nlohmann::json(fetchers::PublicKey { VAL }); \
|
|
}, [](const auto & file) { \
|
|
return json::parse(readFile(file)); \
|
|
}, [](const auto & file, const auto & got) { \
|
|
return writeFile(file, got.dump(2) + "\n"); \
|
|
}); \
|
|
}
|
|
|
|
TEST_JSON(PublicKeyTest, simple, (fetchers::PublicKey { .type = "ssh-rsa", .key = "ABCDE" }))
|
|
|
|
TEST_JSON(PublicKeyTest, defaultType, fetchers::PublicKey { .key = "ABCDE" })
|
|
|
|
#undef TEST_JSON
|
|
|
|
TEST_F(PublicKeyTest, PublicKey_noRoundTrip_from_json) {
|
|
readTest("noRoundTrip.json", [&](const auto & encoded_) {
|
|
fetchers::PublicKey expected = { .type = "ssh-ed25519", .key = "ABCDE" };
|
|
fetchers::PublicKey got = nlohmann::json::parse(encoded_);
|
|
ASSERT_EQ(got, expected);
|
|
});
|
|
}
|
|
|
|
}
|