From 2942e18d056d725aa847d77492a75391a670de5f Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Sun, 25 May 2014 09:06:18 +0200 Subject: Give Object and Reference an Onwer accessor This reduces the need to carry around a pointer to the repository as well as the objects. --- object_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'object_test.go') diff --git a/object_test.go b/object_test.go index 85daf78..f525351 100644 --- a/object_test.go +++ b/object_test.go @@ -75,3 +75,29 @@ func TestObjectPoymorphism(t *testing.T) { t.Fatalf("Failed to parse the right revision") } } + +func checkOwner(t *testing.T, repo *Repository, obj Object) { + owner := obj.Owner() + if owner == nil { + t.Fatal("bad owner") + } + + if owner.ptr != repo.ptr { + t.Fatalf("bad owner, got %v expected %v\n", owner.ptr, repo.ptr) + } +} + +func TestObjectOwner(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Workdir()) + commitId, treeId := seedTestRepo(t, repo) + + commit, err := repo.LookupCommit(commitId) + checkFatal(t, err) + + tree, err := repo.LookupTree(treeId) + checkFatal(t, err) + + checkOwner(t, repo, commit) + checkOwner(t, repo, tree) +} -- cgit v1.2.3