Skip to content

Commit

Permalink
Improve GetForEachRef() tests (re tsuru#120 and tsuru#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Jul 24, 2014
1 parent da67d88 commit 0add2c8
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand All @@ -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")
Expand All @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}

0 comments on commit 0add2c8

Please sign in to comment.