Skip to content

Commit d6fc64a

Browse files
committed
libfetchers-tests: Add InputFromAttrsTest for #14429
Previous commit fixed an issue. This commit adds a test to validate that.
1 parent 40f6006 commit d6fc64a

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/libfetchers-tests/input.cc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

src/libfetchers-tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ sources = files(
4242
'access-tokens.cc',
4343
'git-utils.cc',
4444
'git.cc',
45+
'input.cc',
4546
'nix_api_fetchers.cc',
4647
'public-key.cc',
4748
)

0 commit comments

Comments
 (0)