Skip to content

Commit 61f49de

Browse files
authored
Merge pull request #12511 from xokdvium/chore/delete-dead-code
libfetchers-tests: Add back git-utils.cc
2 parents 0da6a4a + d95b7fe commit 61f49de

File tree

3 files changed

+17
-129
lines changed

3 files changed

+17
-129
lines changed

src/libfetchers-tests/git-utils.cc

Lines changed: 11 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace nix {
1313

14+
namespace fs {
15+
using namespace std::filesystem;
16+
}
17+
1418
class GitUtilsTest : public ::testing::Test
1519
{
1620
// We use a single repository for all tests.
17-
Path tmpDir;
21+
fs::path tmpDir;
1822
std::unique_ptr<AutoDelete> delTmpDir;
1923

2024
public:
@@ -42,6 +46,11 @@ class GitUtilsTest : public ::testing::Test
4246
{
4347
return GitRepo::openRepo(tmpDir, true, false);
4448
}
49+
50+
std::string getRepoName() const
51+
{
52+
return tmpDir.filename();
53+
}
4554
};
4655

4756
void writeString(CreateRegularFileSink & fileSink, std::string contents, bool executable)
@@ -79,7 +88,7 @@ TEST_F(GitUtilsTest, sink_basic)
7988
// sink->createHardlink("foo-1.1/links/foo-2", CanonPath("foo-1.1/hello"));
8089

8190
auto result = repo->dereferenceSingletonDirectory(sink->flush());
82-
auto accessor = repo->getAccessor(result, false);
91+
auto accessor = repo->getAccessor(result, false, getRepoName());
8392
auto entries = accessor->readDirectory(CanonPath::root);
8493
ASSERT_EQ(entries.size(), 5);
8594
ASSERT_EQ(accessor->readFile(CanonPath("hello")), "hello world");
@@ -110,131 +119,4 @@ TEST_F(GitUtilsTest, sink_hardlink)
110119
}
111120
};
112121

113-
namespace lfs {
114-
115-
TEST_F(GitUtilsTest, parseGitRemoteUrl)
116-
{
117-
{
118-
GitUrl result = parseGitUrl("[email protected]:path/repo.git");
119-
EXPECT_EQ(result.protocol, "ssh");
120-
EXPECT_EQ(result.user, "git");
121-
EXPECT_EQ(result.host, "example.com");
122-
EXPECT_EQ(result.port, "");
123-
EXPECT_EQ(result.path, "path/repo.git");
124-
}
125-
126-
{
127-
GitUrl result = parseGitUrl("example.com:/path/repo.git");
128-
EXPECT_EQ(result.protocol, "ssh");
129-
EXPECT_EQ(result.user, "");
130-
EXPECT_EQ(result.host, "example.com");
131-
EXPECT_EQ(result.port, "");
132-
EXPECT_EQ(result.path, "/path/repo.git");
133-
}
134-
135-
{
136-
GitUrl result = parseGitUrl("example.com:path/repo.git");
137-
EXPECT_EQ(result.protocol, "ssh");
138-
EXPECT_EQ(result.user, "");
139-
EXPECT_EQ(result.host, "example.com");
140-
EXPECT_EQ(result.port, "");
141-
EXPECT_EQ(result.path, "path/repo.git");
142-
}
143-
144-
{
145-
GitUrl result = parseGitUrl("https://example.com/path/repo.git");
146-
EXPECT_EQ(result.protocol, "https");
147-
EXPECT_EQ(result.user, "");
148-
EXPECT_EQ(result.host, "example.com");
149-
EXPECT_EQ(result.port, "");
150-
EXPECT_EQ(result.path, "path/repo.git");
151-
}
152-
153-
{
154-
GitUrl result = parseGitUrl("ssh://[email protected]/path/repo.git");
155-
EXPECT_EQ(result.protocol, "ssh");
156-
EXPECT_EQ(result.user, "git");
157-
EXPECT_EQ(result.host, "example.com");
158-
EXPECT_EQ(result.port, "");
159-
EXPECT_EQ(result.path, "path/repo.git");
160-
}
161-
162-
{
163-
GitUrl result = parseGitUrl("ssh://example/path/repo.git");
164-
EXPECT_EQ(result.protocol, "ssh");
165-
EXPECT_EQ(result.user, "");
166-
EXPECT_EQ(result.host, "example");
167-
EXPECT_EQ(result.port, "");
168-
EXPECT_EQ(result.path, "path/repo.git");
169-
}
170-
171-
{
172-
GitUrl result = parseGitUrl("http://example.com:8080/path/repo.git");
173-
EXPECT_EQ(result.protocol, "http");
174-
EXPECT_EQ(result.user, "");
175-
EXPECT_EQ(result.host, "example.com");
176-
EXPECT_EQ(result.port, "8080");
177-
EXPECT_EQ(result.path, "path/repo.git");
178-
}
179-
180-
{
181-
GitUrl result = parseGitUrl("invalid-url");
182-
EXPECT_EQ(result.protocol, "");
183-
EXPECT_EQ(result.user, "");
184-
EXPECT_EQ(result.host, "");
185-
EXPECT_EQ(result.port, "");
186-
EXPECT_EQ(result.path, "");
187-
}
188-
189-
{
190-
GitUrl result = parseGitUrl("");
191-
EXPECT_EQ(result.protocol, "");
192-
EXPECT_EQ(result.user, "");
193-
EXPECT_EQ(result.host, "");
194-
EXPECT_EQ(result.port, "");
195-
EXPECT_EQ(result.path, "");
196-
}
197-
}
198-
TEST_F(GitUtilsTest, gitUrlToHttp)
199-
{
200-
{
201-
const GitUrl url = parseGitUrl("[email protected]:user/repo.git");
202-
EXPECT_EQ(url.toHttp(), "https://github.com/user/repo.git");
203-
}
204-
{
205-
const GitUrl url = parseGitUrl("https://github.com/user/repo.git");
206-
EXPECT_EQ(url.toHttp(), "https://github.com/user/repo.git");
207-
}
208-
{
209-
const GitUrl url = parseGitUrl("http://github.com/user/repo.git");
210-
EXPECT_EQ(url.toHttp(), "http://github.com/user/repo.git");
211-
}
212-
{
213-
const GitUrl url = parseGitUrl("ssh://[email protected]:22/user/repo.git");
214-
EXPECT_EQ(url.toHttp(), "https://github.com:22/user/repo.git");
215-
}
216-
{
217-
const GitUrl url = parseGitUrl("invalid-url");
218-
EXPECT_EQ(url.toHttp(), "");
219-
}
220-
}
221-
222-
TEST_F(GitUtilsTest, gitUrlToSsh)
223-
{
224-
{
225-
const GitUrl url = parseGitUrl("https://example.com/user/repo.git");
226-
const auto [host, path] = url.toSsh();
227-
EXPECT_EQ(host, "example.com");
228-
EXPECT_EQ(path, "user/repo.git");
229-
}
230-
{
231-
const GitUrl url = parseGitUrl("[email protected]:user/repo.git");
232-
const auto [host, path] = url.toSsh();
233-
EXPECT_EQ(host, "[email protected]");
234-
EXPECT_EQ(path, "user/repo.git");
235-
}
236-
}
237-
238-
} // namespace lfs
239-
240122
} // namespace nix

src/libfetchers-tests/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ deps_private += rapidcheck
3131
gtest = dependency('gtest', main : true)
3232
deps_private += gtest
3333

34+
libgit2 = dependency('libgit2')
35+
deps_private += libgit2
36+
3437
add_project_arguments(
3538
# TODO(Qyriad): Yes this is how the autoconf+Make system did it.
3639
# It would be nice for our headers to be idempotent instead.
@@ -44,6 +47,7 @@ subdir('nix-meson-build-support/common')
4447

4548
sources = files(
4649
'public-key.cc',
50+
'git-utils.cc'
4751
)
4852

4953
include_dirs = [include_directories('.')]

src/libfetchers-tests/package.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
nix-fetchers,
88
nix-store-test-support,
99

10+
libgit2,
1011
rapidcheck,
1112
gtest,
1213
runCommand,
@@ -42,6 +43,7 @@ mkMesonExecutable (finalAttrs: {
4243
nix-store-test-support
4344
rapidcheck
4445
gtest
46+
libgit2
4547
];
4648

4749
mesonFlags = [

0 commit comments

Comments
 (0)