add unit test case

This commit is contained in:
william-allspice 2024-08-29 11:50:53 -05:00
parent fb57043abf
commit 96fdaa322d
1 changed files with 27 additions and 0 deletions

View File

@ -100,3 +100,30 @@ func TestFollowLink(t *testing.T) {
_, err = target.FollowLink()
assert.EqualError(t, err, "link_short: broken link")
}
func TestGetPathInRepo(t *testing.T) {
r, err := openRepositoryWithDefaultContext("tests/repos/repo1_bare")
assert.NoError(t, err)
defer r.Close()
commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123")
assert.NoError(t, err)
// nested entry
entry, err := commit.Tree.GetTreeEntryByPath("foo/bar/link_to_hello")
assert.NoError(t, err)
path := entry.GetPathInRepo()
assert.Equal(t, "foo/bar/link_to_hello", path)
// folder
entry, err = commit.Tree.GetTreeEntryByPath("foo/bar")
assert.NoError(t, err)
path = entry.GetPathInRepo()
assert.Equal(t, "foo/bar", path)
// top level file
entry, err = commit.Tree.GetTreeEntryByPath("file2.txt")
assert.NoError(t, err)
path = entry.GetPathInRepo()
assert.Equal(t, "file2.txt", path)
}