From b2b2fb9f3db4573d53ae2c37311be47347ab00d3 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sun, 31 Aug 2014 22:57:42 -0300 Subject: [PATCH] Increase repository.GetForEachRef coverage --- repository/repository_test.go | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/repository/repository_test.go b/repository/repository_test.go index 286d4ea..0b9ac32 100644 --- a/repository/repository_test.go +++ b/repository/repository_test.go @@ -1259,6 +1259,45 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *gocheck.C) { c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (exit status 129).") } +func (s *S) TestGetForEachRefOutputInvalid(c *gocheck.C) { + oldBare := bare + bare = "/tmp" + repo := "gandalf-test-repo" + file := "README" + content := "much WOW" + cleanUp, errCreate := CreateTestRepository(bare, repo, file, content) + defer func() { + cleanUp() + bare = oldBare + }() + c.Assert(errCreate, gocheck.IsNil) + tmpdir, err := commandmocker.Add("git", "-") + c.Assert(err, gocheck.IsNil) + defer commandmocker.Remove(tmpdir) + _, err = GetForEachRef(repo, "") + c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (Invalid git for-each-ref output [-]).") +} + +func (s *S) TestGetForEachRefOutputEmpty(c *gocheck.C) { + oldBare := bare + bare = "/tmp" + repo := "gandalf-test-repo" + file := "README" + content := "much WOW" + cleanUp, errCreate := CreateTestRepository(bare, repo, file, content) + defer func() { + cleanUp() + bare = oldBare + }() + c.Assert(errCreate, gocheck.IsNil) + tmpdir, err := commandmocker.Add("git", "\n") + c.Assert(err, gocheck.IsNil) + defer commandmocker.Remove(tmpdir) + refs, err := GetForEachRef(repo, "") + c.Assert(err, gocheck.IsNil) + c.Assert(refs, gocheck.HasLen, 0) +} + func (s *S) TestGetDiffIntegration(c *gocheck.C) { oldBare := bare bare = "/tmp"