Skip to content

Commit

Permalink
Add TestLogFileWithError for coverage
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Aug 4, 2019
1 parent d7c00b0 commit d1f0897
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package git
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -13,7 +14,6 @@ import (
"testing"
"time"


"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
openpgperr "golang.org/x/crypto/openpgp/errors"
Expand Down Expand Up @@ -1653,6 +1653,28 @@ func (s *RepositorySuite) TestLogFileWithOtherParamsPass(c *C) {
c.Assert(iterErr, Equals, io.EOF)
}

type mockErrCommitIter struct{}

func (m *mockErrCommitIter) Next() (*object.Commit, error) {
return nil, errors.New("mock next error")
}
func (m *mockErrCommitIter) ForEach(func(*object.Commit) error) error {
return errors.New("mock foreach error")
}

func (m *mockErrCommitIter) Close() {}

func (s *RepositorySuite) TestLogFileWithError(c *C) {
fileName := "README"
cIter := object.NewCommitFileIterFromIter(fileName, &mockErrCommitIter{}, false)
defer cIter.Close()

err := cIter.ForEach(func(commit *object.Commit) error {
return nil
})
c.Assert(err, NotNil)
}

func (s *RepositorySuite) TestCommit(c *C) {
r, _ := Init(memory.NewStorage(), nil)
err := r.clone(context.Background(), &CloneOptions{
Expand Down

0 comments on commit d1f0897

Please sign in to comment.