From 0add2c8950820d4e537b8362128cf3608e46357a Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Thu, 24 Jul 2014 17:14:53 -0300 Subject: [PATCH] Improve GetForEachRef() tests (re #120 and #123) --- repository/repository_test.go | 39 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/repository/repository_test.go b/repository/repository_test.go index 095c907..08eb3b6 100644 --- a/repository/repository_test.go +++ b/repository/repository_test.go @@ -820,7 +820,7 @@ func (s *S) TestGetBranchIntegration(c *gocheck.C) { c.Assert(errCreateBranches, gocheck.IsNil) branches, err := GetBranch(repo) c.Assert(err, gocheck.IsNil) - c.Assert(len(branches), gocheck.Equals, 3) + c.Assert(branches, gocheck.HasLen, 3) c.Assert(branches[0]["ref"], gocheck.Matches, "[a-f0-9]{40}") c.Assert(branches[0]["name"], gocheck.Equals, "doge_barks") c.Assert(branches[0]["commiterName"], gocheck.Equals, "doge") @@ -844,7 +844,7 @@ func (s *S) TestGetBranchIntegration(c *gocheck.C) { c.Assert(branches[2]["subject"], gocheck.Equals, "will bark") } -func (s *S) TestGetForEachRefIntegrationEmptySubject(c *gocheck.C) { +func (s *S) TestGetForEachRefIntegrationWithEmptySubject(c *gocheck.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -860,7 +860,7 @@ func (s *S) TestGetForEachRefIntegrationEmptySubject(c *gocheck.C) { c.Assert(errCreateBranches, gocheck.IsNil) refs, err := GetForEachRef(repo, "refs/") c.Assert(err, gocheck.IsNil) - c.Assert(len(refs), gocheck.Equals, 2) + c.Assert(refs, gocheck.HasLen, 2) c.Assert(refs[0]["ref"], gocheck.Matches, "[a-f0-9]{40}") c.Assert(refs[0]["name"], gocheck.Equals, "doge_howls") c.Assert(refs[0]["commiterName"], gocheck.Equals, "doge") @@ -877,7 +877,7 @@ func (s *S) TestGetForEachRefIntegrationEmptySubject(c *gocheck.C) { c.Assert(refs[1]["subject"], gocheck.Equals, "") } -func (s *S) TestGetForEachRefIntegrationSubjectWithTab(c *gocheck.C) { +func (s *S) TestGetForEachRefIntegrationWithTabbedSubject(c *gocheck.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -893,7 +893,7 @@ func (s *S) TestGetForEachRefIntegrationSubjectWithTab(c *gocheck.C) { c.Assert(errCreateBranches, gocheck.IsNil) refs, err := GetForEachRef(repo, "refs/") c.Assert(err, gocheck.IsNil) - c.Assert(len(refs), gocheck.Equals, 2) + c.Assert(refs, gocheck.HasLen, 2) c.Assert(refs[0]["ref"], gocheck.Matches, "[a-f0-9]{40}") c.Assert(refs[0]["name"], gocheck.Equals, "doge_howls") c.Assert(refs[0]["commiterName"], gocheck.Equals, "doge") @@ -926,7 +926,7 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternEmpty(c *gocheck.C) { c.Assert(errCreateBranches, gocheck.IsNil) refs, err := GetForEachRef("gandalf-test-repo", "") c.Assert(err, gocheck.IsNil) - c.Assert(len(refs), gocheck.Equals, 2) + c.Assert(refs, gocheck.HasLen, 2) } func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *gocheck.C) { @@ -943,5 +943,30 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *gocheck.C) { c.Assert(errCreate, gocheck.IsNil) refs, err := GetForEachRef("gandalf-test-repo", "invalid_pattern") c.Assert(err, gocheck.IsNil) - c.Assert(len(refs), gocheck.Equals, 1) + c.Assert(refs, gocheck.HasLen, 1) + c.Assert(refs[0], gocheck.HasLen, 0) +} + +func (s *S) TestGetForEachRefIntegrationWhenInvalidRepo(c *gocheck.C) { + _, err := GetForEachRef("invalid-repo", "refs/") + c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the refs of repository invalid-repo (Repository does not exist).") +} + +func (s *S) TestGetForEachRefIntegrationWhenPatternInexistent(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) + errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_howls") + c.Assert(errCreateBranches, gocheck.IsNil) + refs, err := GetForEachRef("gandalf-test-repo", "xpto") + c.Assert(err, gocheck.IsNil) + c.Assert(refs, gocheck.HasLen, 2) }