Skip to content

Commit 888b279

Browse files
DomLatrlouis-z
andauthored
Make sure GetTree() in mock reproduces behavior on GitLab (#825)
* Make sure GetTree() in mock reproduces behavior on GitLab * Update test in RepositoryMockTests.cs to match behavior * Add comment in code to explain behavior * Update NGitLab.Mock/Repository.cs Co-authored-by: Louis Zanella <louis.zanella@gmail.com> * Changes related to comment --------- Co-authored-by: Louis Zanella <louis.zanella@gmail.com>
1 parent bd9ef23 commit 888b279

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

NGitLab.Mock.Tests/UsingVerify/RepositoryMockTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System.IO;
22
using System.Linq;
33
using System.Threading.Tasks;
4-
using NGitLab.Mock.Clients;
54
using NGitLab.Mock.Config;
65
using NUnit.Framework;
76
using static VerifyNUnit.Verifier;
87
using RepositoryGetTreeOptions = NGitLab.Models.RepositoryGetTreeOptions;
9-
using Throws = NUnit.Framework.Throws;
108

119
namespace NGitLab.Mock.Tests.UsingVerify;
1210

@@ -26,10 +24,10 @@ public void Test_get_tree_when_subdirectory_does_not_exist_throws_not_found()
2624
var repository = client.GetRepository(1);
2725

2826
// Act
29-
var handler = () => repository.GetTreeAsync(new RepositoryGetTreeOptions { Path = "non-existing-directory" });
27+
var treeCollection = repository.GetTreeAsync(new RepositoryGetTreeOptions { Path = "non-existing-directory" });
3028

3129
// Assert
32-
Assert.That(handler, Throws.InstanceOf<GitLabNotFoundException>());
30+
Assert.That(treeCollection , Is.Empty);
3331
}
3432

3533
[Test]

NGitLab.Mock/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ internal IEnumerable<Tree> GetTree(RepositoryGetTreeOptions repositoryGetTreeOpt
552552

553553
if (tree is null)
554554
{
555+
// As confirmed by the GetAllTreeObjectsAtInvalidPath() test, GitLab's behavior for
556+
// GetTree() when Path doesn't exist is to return an empty collection.
557+
if (!string.IsNullOrWhiteSpace(repositoryGetTreeOptions.Path))
558+
return [];
559+
555560
throw new GitLabNotFoundException();
556561
}
557562

0 commit comments

Comments
 (0)