|
11 | 11 |
|
12 | 12 | namespace nix { |
13 | 13 |
|
| 14 | +namespace fs { |
| 15 | +using namespace std::filesystem; |
| 16 | +} |
| 17 | + |
14 | 18 | class GitUtilsTest : public ::testing::Test |
15 | 19 | { |
16 | 20 | // We use a single repository for all tests. |
17 | | - Path tmpDir; |
| 21 | + fs::path tmpDir; |
18 | 22 | std::unique_ptr<AutoDelete> delTmpDir; |
19 | 23 |
|
20 | 24 | public: |
@@ -42,6 +46,11 @@ class GitUtilsTest : public ::testing::Test |
42 | 46 | { |
43 | 47 | return GitRepo::openRepo(tmpDir, true, false); |
44 | 48 | } |
| 49 | + |
| 50 | + std::string getRepoName() const |
| 51 | + { |
| 52 | + return tmpDir.filename(); |
| 53 | + } |
45 | 54 | }; |
46 | 55 |
|
47 | 56 | void writeString(CreateRegularFileSink & fileSink, std::string contents, bool executable) |
@@ -79,7 +88,7 @@ TEST_F(GitUtilsTest, sink_basic) |
79 | 88 | // sink->createHardlink("foo-1.1/links/foo-2", CanonPath("foo-1.1/hello")); |
80 | 89 |
|
81 | 90 | auto result = repo->dereferenceSingletonDirectory(sink->flush()); |
82 | | - auto accessor = repo->getAccessor(result, false); |
| 91 | + auto accessor = repo->getAccessor(result, false, getRepoName()); |
83 | 92 | auto entries = accessor->readDirectory(CanonPath::root); |
84 | 93 | ASSERT_EQ(entries.size(), 5); |
85 | 94 | ASSERT_EQ(accessor->readFile(CanonPath("hello")), "hello world"); |
@@ -110,131 +119,4 @@ TEST_F(GitUtilsTest, sink_hardlink) |
110 | 119 | } |
111 | 120 | }; |
112 | 121 |
|
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 | | - |
240 | 122 | } // namespace nix |
0 commit comments