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

Commit

Permalink
Improve mock/tests for GetBranch (re #123)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Jul 23, 2014
1 parent fe183f1 commit 9ab48fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
27 changes: 1 addition & 26 deletions repository/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func CreateTestRepository(tmp_path string, repo string, file string, content str
return cleanup, err
}

func CreateBranchesOnTestRepository(tmp_path string, repo string, file string, content string, branches ...string) error {
func CreateBranchesOnTestRepository(tmp_path string, repo string, branches ...string) error {
testPath := path.Join(tmp_path, repo+".git")
gitPath, err := exec.LookPath("git")
if err != nil {
Expand All @@ -116,37 +116,12 @@ func CreateBranchesOnTestRepository(tmp_path string, repo string, file string, c
return err
}
for _, branch := range branches {
fp, err := os.OpenFile(path.Join(testPath, file), os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer fp.Close()
_, err = fp.WriteString("such string")
if err != nil {
return err
}
cmd = exec.Command(gitPath, "checkout", "-b", branch)
cmd.Dir = testPath
err = cmd.Run()
if err != nil {
return err
}
cmd = exec.Command(gitPath, "add", ".")
cmd.Dir = testPath
err = cmd.Run()
if err != nil {
return err
}
if len(content) > 0 {
cmd = exec.Command(gitPath, "commit", "-m", content+" on "+branch)
} else {
cmd = exec.Command(gitPath, "commit", "-m", "", "--allow-empty-message")
}
cmd.Dir = testPath
err = cmd.Run()
if err != nil {
return err
}
}
return err
}
Expand Down
8 changes: 4 additions & 4 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func (s *S) TestGetBranchIntegration(c *gocheck.C) {
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
errCreateBranches := CreateBranchesOnTestRepository(bare, repo, file, content, "doge_bites", "doge_barks")
errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_bites", "doge_barks")
c.Assert(errCreateBranches, gocheck.IsNil)
branches, err := GetBranch(repo)
c.Assert(err, gocheck.IsNil)
Expand All @@ -827,14 +827,14 @@ func (s *S) TestGetBranchIntegration(c *gocheck.C) {
c.Assert(branches[0]["commiterEmail"], gocheck.Equals, "<much@email.com>")
c.Assert(branches[0]["authorName"], gocheck.Equals, "doge")
c.Assert(branches[0]["authorEmail"], gocheck.Equals, "<much@email.com>")
c.Assert(branches[0]["subject"], gocheck.Equals, "will bark on doge_barks")
c.Assert(branches[0]["subject"], gocheck.Equals, "will bark")
c.Assert(branches[1]["ref"], gocheck.Matches, "[a-f0-9]{40}")
c.Assert(branches[1]["name"], gocheck.Equals, "doge_bites")
c.Assert(branches[1]["commiterName"], gocheck.Equals, "doge")
c.Assert(branches[1]["commiterEmail"], gocheck.Equals, "<much@email.com>")
c.Assert(branches[1]["authorName"], gocheck.Equals, "doge")
c.Assert(branches[1]["authorEmail"], gocheck.Equals, "<much@email.com>")
c.Assert(branches[1]["subject"], gocheck.Equals, "will bark on doge_bites")
c.Assert(branches[1]["subject"], gocheck.Equals, "will bark")
c.Assert(branches[2]["ref"], gocheck.Matches, "[a-f0-9]{40}")
c.Assert(branches[2]["name"], gocheck.Equals, "master")
c.Assert(branches[2]["commiterName"], gocheck.Equals, "doge")
Expand All @@ -856,7 +856,7 @@ func (s *S) TestGetBranchIntegrationEmptySubject(c *gocheck.C) {
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
errCreateBranches := CreateBranchesOnTestRepository(bare, repo, file, content, "doge_howls")
errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_howls")
c.Assert(errCreateBranches, gocheck.IsNil)
branches, err := GetBranch(repo)
c.Assert(err, gocheck.IsNil)
Expand Down

0 comments on commit 9ab48fc

Please sign in to comment.