From 7ba1014b73e4d466320a29f7e3f47fcefe58695d Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Sat, 23 Jan 2016 00:50:29 -0800 Subject: Repository now works against the generic ObjectStore interface --- commit_test.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'commit_test.go') diff --git a/commit_test.go b/commit_test.go index 67b9e77..1202d59 100644 --- a/commit_test.go +++ b/commit_test.go @@ -40,11 +40,14 @@ func (s *SuiteCommit) SetUpSuite(c *C) { } } +// FIXME: Test the new CommitIter +/* func (s *SuiteCommit) TestIterClose(c *C) { i := &iter{ch: make(chan core.Object, 1)} i.Close() i.Close() } +*/ var fileTests = []struct { repo string // the repo name as in localRepos -- cgit From 16f4d888dcec24c2242d5b43673d9a4caed19ae4 Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Mon, 15 Feb 2016 19:35:00 -0800 Subject: Added tests for CommitIter --- commit_test.go | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 7 deletions(-) (limited to 'commit_test.go') diff --git a/commit_test.go b/commit_test.go index 1202d59..19565fb 100644 --- a/commit_test.go +++ b/commit_test.go @@ -1,6 +1,7 @@ package git import ( + "io" "os" "gopkg.in/src-d/go-git.v2/core" @@ -40,14 +41,74 @@ func (s *SuiteCommit) SetUpSuite(c *C) { } } -// FIXME: Test the new CommitIter -/* -func (s *SuiteCommit) TestIterClose(c *C) { - i := &iter{ch: make(chan core.Object, 1)} - i.Close() - i.Close() +var iterTests = []struct { + repo string // the repo name in the test suite's map of fixtures + commits []string // the commit hashes to iterate over in the test +}{ + {"https://github.com/tyba/git-fixture.git", []string{ + "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", + "918c48b83bd081e863dbe1b80f8998f058cd8294", + "af2d6a6954d532f8ffb47615169c8fdf9d383a1a", + "1669dce138d9b841a518c64b10914d88f5e488ea", + "35e85108805c84807bc66a02d91535e1e24b38b9", + "b029517f6300c2da0f4b651b8642506cd6aaf45d", + "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", + "b029517f6300c2da0f4b651b8642506cd6aaf45d", // Intentional duplicate + "b8e471f58bcbca63b07bda20e428190409c2db47", + "b029517f6300c2da0f4b651b8642506cd6aaf45d"}}, // Intentional duplicate +} + +func (s *SuiteCommit) TestIterSlice(c *C) { + for i, t := range iterTests { + r := s.repos[t.repo] + iter := NewCommitIter(r, core.NewObjectSliceIter(makeObjectSlice(t.commits, r.Storage))) + s.checkIter(c, r, i, iter, t.commits) + } +} + +func (s *SuiteCommit) TestIterLookup(c *C) { + for i, t := range iterTests { + r := s.repos[t.repo] + iter := NewCommitIter(r, core.NewObjectLookupIter(r.Storage, makeHashSlice(t.commits))) + s.checkIter(c, r, i, iter, t.commits) + } +} + +func (s *SuiteCommit) checkIter(c *C, r *Repository, subtest int, iter *CommitIter, commits []string) { + for k := 0; k < len(commits); k++ { + commit, err := iter.Next() + c.Assert(err, IsNil, Commentf("subtest %d, iter %d, err=%v", subtest, k, err)) + c.Assert(commit.Hash.String(), Equals, commits[k], Commentf("subtest %d, iter %d, hash=%v, expected=%s", subtest, k, commit.Hash.String(), commits[k])) + } + _, err := iter.Next() + c.Assert(err, Equals, io.EOF) +} + +func (s *SuiteCommit) TestIterSliceClose(c *C) { + for i, t := range iterTests { + r := s.repos[t.repo] + iter := NewCommitIter(r, core.NewObjectSliceIter(makeObjectSlice(t.commits, r.Storage))) + s.checkIterClose(c, i, iter) + } +} + +func (s *SuiteCommit) TestIterLookupClose(c *C) { + for i, t := range iterTests { + r := s.repos[t.repo] + iter := NewCommitIter(r, core.NewObjectLookupIter(r.Storage, makeHashSlice(t.commits))) + s.checkIterClose(c, i, iter) + } +} + +func (s *SuiteCommit) checkIterClose(c *C, subtest int, iter *CommitIter) { + iter.Close() + _, err := iter.Next() + c.Assert(err, Equals, io.EOF, Commentf("subtest %d, close 1, err=%v", subtest, err)) + + iter.Close() + _, err = iter.Next() + c.Assert(err, Equals, io.EOF, Commentf("subtest %d, close 2, err=%v", subtest, err)) } -*/ var fileTests = []struct { repo string // the repo name as in localRepos @@ -105,3 +166,22 @@ func (s *SuiteCommit) TestFile(c *C) { } } } + +func makeObjectSlice(hashes []string, storage core.ObjectStorage) []core.Object { + series := make([]core.Object, 0, len(hashes)) + for _, member := range hashes { + obj, ok := storage.Get(core.NewHash(member)) + if ok { + series = append(series, obj) + } + } + return series +} + +func makeHashSlice(hashes []string) []core.Hash { + series := make([]core.Hash, 0, len(hashes)) + for _, member := range hashes { + series = append(series, core.NewHash(member)) + } + return series +} -- cgit From e82d4918b403a641a5295b3f199586b0ab26b15c Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Tue, 16 Feb 2016 03:28:21 -0800 Subject: Functions in core.ObjectStorage interface now return an error --- commit_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'commit_test.go') diff --git a/commit_test.go b/commit_test.go index 19565fb..65f6400 100644 --- a/commit_test.go +++ b/commit_test.go @@ -170,8 +170,8 @@ func (s *SuiteCommit) TestFile(c *C) { func makeObjectSlice(hashes []string, storage core.ObjectStorage) []core.Object { series := make([]core.Object, 0, len(hashes)) for _, member := range hashes { - obj, ok := storage.Get(core.NewHash(member)) - if ok { + obj, err := storage.Get(core.NewHash(member)) + if err == nil { series = append(series, obj) } } -- cgit