|
| 1 | +#include "nix/fetchers/fetch-settings.hh" |
| 2 | +#include "nix/fetchers/attrs.hh" |
| 3 | +#include "nix/fetchers/fetchers.hh" |
| 4 | + |
| 5 | +#include <gtest/gtest.h> |
| 6 | + |
| 7 | +#include <string> |
| 8 | + |
| 9 | +namespace nix { |
| 10 | + |
| 11 | +using fetchers::Attr; |
| 12 | + |
| 13 | +struct InputFromAttrsTestCase |
| 14 | +{ |
| 15 | + fetchers::Attrs attrs; |
| 16 | + std::string expectedUrl; |
| 17 | + std::string description; |
| 18 | + fetchers::Attrs expectedAttrs = attrs; |
| 19 | +}; |
| 20 | + |
| 21 | +class InputFromAttrsTest : public ::testing::WithParamInterface<InputFromAttrsTestCase>, public ::testing::Test |
| 22 | +{}; |
| 23 | + |
| 24 | +TEST_P(InputFromAttrsTest, attrsAreCorrectAndRoundTrips) |
| 25 | +{ |
| 26 | + fetchers::Settings fetchSettings; |
| 27 | + |
| 28 | + const auto & testCase = GetParam(); |
| 29 | + |
| 30 | + auto input = fetchers::Input::fromAttrs(fetchSettings, fetchers::Attrs(testCase.attrs)); |
| 31 | + |
| 32 | + EXPECT_EQ(input.toAttrs(), testCase.expectedAttrs); |
| 33 | + EXPECT_EQ(input.toURLString(), testCase.expectedUrl); |
| 34 | + |
| 35 | + auto input2 = fetchers::Input::fromAttrs(fetchSettings, input.toAttrs()); |
| 36 | + EXPECT_EQ(input, input2); |
| 37 | + EXPECT_EQ(input.toAttrs(), input2.toAttrs()); |
| 38 | +} |
| 39 | + |
| 40 | +INSTANTIATE_TEST_SUITE_P( |
| 41 | + InputFromAttrs, |
| 42 | + InputFromAttrsTest, |
| 43 | + ::testing::Values( |
| 44 | + // Test for issue #14429. |
| 45 | + InputFromAttrsTestCase{ |
| 46 | + .attrs = |
| 47 | + { |
| 48 | + { "url", Attr( "git+ssh://[email protected]/NixOS/nixpkgs")}, |
| 49 | + {"type", Attr("git")}, |
| 50 | + }, |
| 51 | + . expectedUrl = "git+ssh://[email protected]/NixOS/nixpkgs", |
| 52 | + .description = "strips_git_plus_prefix", |
| 53 | + .expectedAttrs = |
| 54 | + { |
| 55 | + { "url", Attr( "ssh://[email protected]/NixOS/nixpkgs")}, |
| 56 | + {"type", Attr("git")}, |
| 57 | + }, |
| 58 | + }), |
| 59 | + [](const ::testing::TestParamInfo<InputFromAttrsTestCase> & info) { return info.param.description; }); |
| 60 | + |
| 61 | +} // namespace nix |
0 commit comments