Skip to content

Commit

Permalink
Merge pull request #12511 from xokdvium/chore/delete-dead-code
Browse files Browse the repository at this point in the history
libfetchers-tests: Add back git-utils.cc
  • Loading branch information
Ericson2314 authored Feb 20, 2025
2 parents 0da6a4a + d95b7fe commit 61f49de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 129 deletions.
140 changes: 11 additions & 129 deletions src/libfetchers-tests/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -42,6 +46,11 @@ class GitUtilsTest : public ::testing::Test
{
return GitRepo::openRepo(tmpDir, true, false);
}

std::string getRepoName() const
{
return tmpDir.filename();
}
};

void writeString(CreateRegularFileSink & fileSink, std::string contents, bool executable)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/libfetchers-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -44,6 +47,7 @@ subdir('nix-meson-build-support/common')

sources = files(
'public-key.cc',
'git-utils.cc'
)

include_dirs = [include_directories('.')]
Expand Down
2 changes: 2 additions & 0 deletions src/libfetchers-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
nix-fetchers,
nix-store-test-support,

libgit2,
rapidcheck,
gtest,
runCommand,
Expand Down Expand Up @@ -42,6 +43,7 @@ mkMesonExecutable (finalAttrs: {
nix-store-test-support
rapidcheck
gtest
libgit2
];

mesonFlags = [
Expand Down

0 comments on commit 61f49de

Please sign in to comment.