Skip to content

Commit

Permalink
Make sure GetTree() in mock reproduces behavior on GitLab (#825)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
DomLatr and louis-z authored Jan 7, 2025
1 parent bd9ef23 commit 888b279
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions NGitLab.Mock.Tests/UsingVerify/RepositoryMockTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NGitLab.Mock.Clients;
using NGitLab.Mock.Config;
using NUnit.Framework;
using static VerifyNUnit.Verifier;
using RepositoryGetTreeOptions = NGitLab.Models.RepositoryGetTreeOptions;
using Throws = NUnit.Framework.Throws;

namespace NGitLab.Mock.Tests.UsingVerify;

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

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

// Assert
Assert.That(handler, Throws.InstanceOf<GitLabNotFoundException>());
Assert.That(treeCollection , Is.Empty);
}

[Test]
Expand Down
5 changes: 5 additions & 0 deletions NGitLab.Mock/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ internal IEnumerable<Tree> GetTree(RepositoryGetTreeOptions repositoryGetTreeOpt

if (tree is null)
{
// As confirmed by the GetAllTreeObjectsAtInvalidPath() test, GitLab's behavior for
// GetTree() when Path doesn't exist is to return an empty collection.
if (!string.IsNullOrWhiteSpace(repositoryGetTreeOptions.Path))
return [];

throw new GitLabNotFoundException();
}

Expand Down

0 comments on commit 888b279

Please sign in to comment.