mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
Merge pull request #12511 from xokdvium/chore/delete-dead-code
libfetchers-tests: Add back git-utils.cc
This commit is contained in:
commit
61f49de7ae
3 changed files with 17 additions and 129 deletions
|
@ -11,10 +11,14 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
namespace fs {
|
||||
using namespace std::filesystem;
|
||||
}
|
||||
|
||||
class GitUtilsTest : public ::testing::Test
|
||||
{
|
||||
// We use a single repository for all tests.
|
||||
Path tmpDir;
|
||||
fs::path tmpDir;
|
||||
std::unique_ptr<AutoDelete> delTmpDir;
|
||||
|
||||
public:
|
||||
|
@ -42,6 +46,11 @@ public:
|
|||
{
|
||||
return GitRepo::openRepo(tmpDir, true, false);
|
||||
}
|
||||
|
||||
std::string getRepoName() const
|
||||
{
|
||||
return tmpDir.filename();
|
||||
}
|
||||
};
|
||||
|
||||
void writeString(CreateRegularFileSink & fileSink, std::string contents, bool executable)
|
||||
|
@ -79,7 +88,7 @@ TEST_F(GitUtilsTest, sink_basic)
|
|||
// sink->createHardlink("foo-1.1/links/foo-2", CanonPath("foo-1.1/hello"));
|
||||
|
||||
auto result = repo->dereferenceSingletonDirectory(sink->flush());
|
||||
auto accessor = repo->getAccessor(result, false);
|
||||
auto accessor = repo->getAccessor(result, false, getRepoName());
|
||||
auto entries = accessor->readDirectory(CanonPath::root);
|
||||
ASSERT_EQ(entries.size(), 5);
|
||||
ASSERT_EQ(accessor->readFile(CanonPath("hello")), "hello world");
|
||||
|
@ -110,131 +119,4 @@ TEST_F(GitUtilsTest, sink_hardlink)
|
|||
}
|
||||
};
|
||||
|
||||
namespace lfs {
|
||||
|
||||
TEST_F(GitUtilsTest, parseGitRemoteUrl)
|
||||
{
|
||||
{
|
||||
GitUrl result = parseGitUrl("git@example.com:path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "ssh");
|
||||
EXPECT_EQ(result.user, "git");
|
||||
EXPECT_EQ(result.host, "example.com");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("example.com:/path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "ssh");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "example.com");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "/path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("example.com:path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "ssh");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "example.com");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("https://example.com/path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "https");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "example.com");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("ssh://git@example.com/path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "ssh");
|
||||
EXPECT_EQ(result.user, "git");
|
||||
EXPECT_EQ(result.host, "example.com");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("ssh://example/path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "ssh");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "example");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("http://example.com:8080/path/repo.git");
|
||||
EXPECT_EQ(result.protocol, "http");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "example.com");
|
||||
EXPECT_EQ(result.port, "8080");
|
||||
EXPECT_EQ(result.path, "path/repo.git");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("invalid-url");
|
||||
EXPECT_EQ(result.protocol, "");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "");
|
||||
}
|
||||
|
||||
{
|
||||
GitUrl result = parseGitUrl("");
|
||||
EXPECT_EQ(result.protocol, "");
|
||||
EXPECT_EQ(result.user, "");
|
||||
EXPECT_EQ(result.host, "");
|
||||
EXPECT_EQ(result.port, "");
|
||||
EXPECT_EQ(result.path, "");
|
||||
}
|
||||
}
|
||||
TEST_F(GitUtilsTest, gitUrlToHttp)
|
||||
{
|
||||
{
|
||||
const GitUrl url = parseGitUrl("git@github.com:user/repo.git");
|
||||
EXPECT_EQ(url.toHttp(), "https://github.com/user/repo.git");
|
||||
}
|
||||
{
|
||||
const GitUrl url = parseGitUrl("https://github.com/user/repo.git");
|
||||
EXPECT_EQ(url.toHttp(), "https://github.com/user/repo.git");
|
||||
}
|
||||
{
|
||||
const GitUrl url = parseGitUrl("http://github.com/user/repo.git");
|
||||
EXPECT_EQ(url.toHttp(), "http://github.com/user/repo.git");
|
||||
}
|
||||
{
|
||||
const GitUrl url = parseGitUrl("ssh://git@github.com:22/user/repo.git");
|
||||
EXPECT_EQ(url.toHttp(), "https://github.com:22/user/repo.git");
|
||||
}
|
||||
{
|
||||
const GitUrl url = parseGitUrl("invalid-url");
|
||||
EXPECT_EQ(url.toHttp(), "");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(GitUtilsTest, gitUrlToSsh)
|
||||
{
|
||||
{
|
||||
const GitUrl url = parseGitUrl("https://example.com/user/repo.git");
|
||||
const auto [host, path] = url.toSsh();
|
||||
EXPECT_EQ(host, "example.com");
|
||||
EXPECT_EQ(path, "user/repo.git");
|
||||
}
|
||||
{
|
||||
const GitUrl url = parseGitUrl("git@example.com:user/repo.git");
|
||||
const auto [host, path] = url.toSsh();
|
||||
EXPECT_EQ(host, "git@example.com");
|
||||
EXPECT_EQ(path, "user/repo.git");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lfs
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
@ -31,6 +31,9 @@ deps_private += rapidcheck
|
|||
gtest = dependency('gtest', main : true)
|
||||
deps_private += gtest
|
||||
|
||||
libgit2 = dependency('libgit2')
|
||||
deps_private += libgit2
|
||||
|
||||
add_project_arguments(
|
||||
# TODO(Qyriad): Yes this is how the autoconf+Make system did it.
|
||||
# It would be nice for our headers to be idempotent instead.
|
||||
|
@ -44,6 +47,7 @@ subdir('nix-meson-build-support/common')
|
|||
|
||||
sources = files(
|
||||
'public-key.cc',
|
||||
'git-utils.cc'
|
||||
)
|
||||
|
||||
include_dirs = [include_directories('.')]
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
nix-fetchers,
|
||||
nix-store-test-support,
|
||||
|
||||
libgit2,
|
||||
rapidcheck,
|
||||
gtest,
|
||||
runCommand,
|
||||
|
@ -42,6 +43,7 @@ mkMesonExecutable (finalAttrs: {
|
|||
nix-store-test-support
|
||||
rapidcheck
|
||||
gtest
|
||||
libgit2
|
||||
];
|
||||
|
||||
mesonFlags = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue