mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Merge pull request #13872 from xokdvium/fix-indirect-flake-refs
libflake: Fix flake id flake refs with revisions
This commit is contained in:
commit
511d885d60
2 changed files with 86 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "nix/fetchers/fetch-settings.hh"
|
||||
#include "nix/flake/flakeref.hh"
|
||||
#include "nix/fetchers/attrs.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -90,6 +91,90 @@ TEST(parseFlakeRef, GitArchiveInput)
|
|||
}
|
||||
}
|
||||
|
||||
struct InputFromURLTestCase
|
||||
{
|
||||
std::string url;
|
||||
fetchers::Attrs attrs;
|
||||
std::string description;
|
||||
std::string expectedUrl = url;
|
||||
};
|
||||
|
||||
class InputFromURLTest : public ::testing::WithParamInterface<InputFromURLTestCase>, public ::testing::Test
|
||||
{};
|
||||
|
||||
TEST_P(InputFromURLTest, attrsAreCorrectAndRoundTrips)
|
||||
{
|
||||
experimentalFeatureSettings.experimentalFeatures.get().insert(Xp::Flakes);
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
const auto & testCase = GetParam();
|
||||
|
||||
auto flakeref = parseFlakeRef(fetchSettings, testCase.url);
|
||||
|
||||
EXPECT_EQ(flakeref.toAttrs(), testCase.attrs);
|
||||
EXPECT_EQ(flakeref.to_string(), testCase.expectedUrl);
|
||||
|
||||
auto input = fetchers::Input::fromURL(fetchSettings, flakeref.to_string());
|
||||
|
||||
EXPECT_EQ(input.toURLString(), testCase.expectedUrl);
|
||||
EXPECT_EQ(input.toAttrs(), testCase.attrs);
|
||||
|
||||
// Round-trip check.
|
||||
auto input2 = fetchers::Input::fromURL(fetchSettings, input.toURLString());
|
||||
EXPECT_EQ(input, input2);
|
||||
EXPECT_EQ(input.toURLString(), input2.toURLString());
|
||||
}
|
||||
|
||||
using fetchers::Attr;
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InputFromURL,
|
||||
InputFromURLTest,
|
||||
::testing::Values(
|
||||
InputFromURLTestCase{
|
||||
.url = "flake:nixpkgs",
|
||||
.attrs =
|
||||
{
|
||||
{"id", Attr("nixpkgs")},
|
||||
{"type", Attr("indirect")},
|
||||
},
|
||||
.description = "basic_indirect",
|
||||
},
|
||||
InputFromURLTestCase{
|
||||
.url = "flake:nixpkgs/branch",
|
||||
.attrs =
|
||||
{
|
||||
{"id", Attr("nixpkgs")},
|
||||
{"type", Attr("indirect")},
|
||||
{"ref", Attr("branch")},
|
||||
},
|
||||
.description = "basic_indirect_branch",
|
||||
},
|
||||
InputFromURLTestCase{
|
||||
.url = "nixpkgs/branch",
|
||||
.attrs =
|
||||
{
|
||||
{"id", Attr("nixpkgs")},
|
||||
{"type", Attr("indirect")},
|
||||
{"ref", Attr("branch")},
|
||||
},
|
||||
.description = "flake_id_ref_branch",
|
||||
.expectedUrl = "flake:nixpkgs/branch",
|
||||
},
|
||||
InputFromURLTestCase{
|
||||
.url = "nixpkgs/branch/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
|
||||
.attrs =
|
||||
{
|
||||
{"id", Attr("nixpkgs")},
|
||||
{"type", Attr("indirect")},
|
||||
{"ref", Attr("branch")},
|
||||
{"rev", Attr("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")},
|
||||
},
|
||||
.description = "flake_id_ref_branch_trailing_slash",
|
||||
.expectedUrl = "flake:nixpkgs/branch/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
|
||||
}),
|
||||
[](const ::testing::TestParamInfo<InputFromURLTestCase> & info) { return info.param.description; });
|
||||
|
||||
TEST(to_string, doesntReencodeUrl)
|
||||
{
|
||||
fetchers::Settings fetchSettings;
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ parseFlakeIdRef(const fetchers::Settings & fetchSettings, const std::string & ur
|
|||
if (std::regex_match(url, match, flakeRegex)) {
|
||||
auto parsedURL = ParsedURL{
|
||||
.scheme = "flake",
|
||||
.authority = ParsedURL::Authority{},
|
||||
.authority = std::nullopt,
|
||||
.path = splitString<std::vector<std::string>>(match[1].str(), "/"),
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue