mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
libfetchers-tests: Add InputFromAttrsTest for #14429
Previous commit fixed an issue. This commit adds a test to validate that.
This commit is contained in:
parent
40f600644d
commit
d6fc64ac38
2 changed files with 62 additions and 0 deletions
61
src/libfetchers-tests/input.cc
Normal file
61
src/libfetchers-tests/input.cc
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include "nix/fetchers/fetch-settings.hh"
|
||||
#include "nix/fetchers/attrs.hh"
|
||||
#include "nix/fetchers/fetchers.hh"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace nix {
|
||||
|
||||
using fetchers::Attr;
|
||||
|
||||
struct InputFromAttrsTestCase
|
||||
{
|
||||
fetchers::Attrs attrs;
|
||||
std::string expectedUrl;
|
||||
std::string description;
|
||||
fetchers::Attrs expectedAttrs = attrs;
|
||||
};
|
||||
|
||||
class InputFromAttrsTest : public ::testing::WithParamInterface<InputFromAttrsTestCase>, public ::testing::Test
|
||||
{};
|
||||
|
||||
TEST_P(InputFromAttrsTest, attrsAreCorrectAndRoundTrips)
|
||||
{
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
const auto & testCase = GetParam();
|
||||
|
||||
auto input = fetchers::Input::fromAttrs(fetchSettings, fetchers::Attrs(testCase.attrs));
|
||||
|
||||
EXPECT_EQ(input.toAttrs(), testCase.expectedAttrs);
|
||||
EXPECT_EQ(input.toURLString(), testCase.expectedUrl);
|
||||
|
||||
auto input2 = fetchers::Input::fromAttrs(fetchSettings, input.toAttrs());
|
||||
EXPECT_EQ(input, input2);
|
||||
EXPECT_EQ(input.toAttrs(), input2.toAttrs());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InputFromAttrs,
|
||||
InputFromAttrsTest,
|
||||
::testing::Values(
|
||||
// Test for issue #14429.
|
||||
InputFromAttrsTestCase{
|
||||
.attrs =
|
||||
{
|
||||
{"url", Attr("git+ssh://git@github.com/NixOS/nixpkgs")},
|
||||
{"type", Attr("git")},
|
||||
},
|
||||
.expectedUrl = "git+ssh://git@github.com/NixOS/nixpkgs",
|
||||
.description = "strips_git_plus_prefix",
|
||||
.expectedAttrs =
|
||||
{
|
||||
{"url", Attr("ssh://git@github.com/NixOS/nixpkgs")},
|
||||
{"type", Attr("git")},
|
||||
},
|
||||
}),
|
||||
[](const ::testing::TestParamInfo<InputFromAttrsTestCase> & info) { return info.param.description; });
|
||||
|
||||
} // namespace nix
|
||||
|
|
@ -42,6 +42,7 @@ sources = files(
|
|||
'access-tokens.cc',
|
||||
'git-utils.cc',
|
||||
'git.cc',
|
||||
'input.cc',
|
||||
'nix_api_fetchers.cc',
|
||||
'public-key.cc',
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue