Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #127 from scorphus/test-get-for-each-ref
Browse files Browse the repository at this point in the history
Warily treat empty or invalid pattern (re #120 and #123)
  • Loading branch information
andrewsmedina committed Jul 24, 2014
2 parents 40ce1be + 433787e commit a590fe8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ func (*GitContentRetriever) GetForEachRef(repo, pattern string) ([]map[string]st
return nil, fmt.Errorf("Error when trying to obtain the refs of repository %s (%s).", repo, err)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// When the separator does not separate the string, Split returns an array
// with one element: the string itself. (golang.org/pkg/strings/#Split)
if len(lines) == 1 && len(lines[0]) == 0 {
return nil, nil
}
objectCount := len(lines)
objects := make([]map[string]string, objectCount)
objectCount = 0
Expand Down
34 changes: 34 additions & 0 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,37 @@ func (s *S) TestGetForEachRefIntegrationSubjectWithTab(c *gocheck.C) {
c.Assert(refs[1]["authorEmail"], gocheck.Equals, "<much@email.com>")
c.Assert(refs[1]["subject"], gocheck.Equals, "will\tbark")
}

func (s *S) TestGetForEachRefIntegrationWhenPatternEmpty(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)
refs, err := GetForEachRef("gandalf-test-repo", "")
c.Assert(refs, gocheck.IsNil)
c.Assert(err, gocheck.IsNil)
}

func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(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)
refs, err := GetForEachRef("gandalf-test-repo", "invalid_pattern")
c.Assert(refs, gocheck.IsNil)
c.Assert(err, gocheck.IsNil)
}

0 comments on commit a590fe8

Please sign in to comment.