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

Commit

Permalink
fixing git user when running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef committed Jul 2, 2014
1 parent ea47cee commit 1c831f2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
54 changes: 37 additions & 17 deletions repository/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,49 @@ func (r *MockContentRetriever) GetArchive(repo, ref string, format ArchiveFormat
return r.ResultContents, nil
}

func CreateTestRepository(tmp_path string, repo string, file string, content string) func() {
gitPath, _ := exec.LookPath("git")
func CreateTestRepository(tmp_path string, repo string, file string, content string) (func(), error) {
testPath := path.Join(tmp_path, repo+".git")
exec.Command("mkdir", "-p", testPath).Output()

cleanup := func() {
exec.Command("rm", "-rf", testPath).Output()
}
gitPath, err := exec.LookPath("git")
if err != nil {
return cleanup, err
}
out, err := exec.Command("mkdir", "-p", testPath).Output()
if err != nil {
return cleanup, err
}
cmd := exec.Command(gitPath, "init")
cmd.Dir = testPath
cmd.Output()

err := ioutil.WriteFile(path.Join(testPath, file), []byte(content), 0644)
out, err = cmd.Output()
if err != nil {
panic(err)
return cleanup, err
}

cmd = exec.Command(gitPath, "add", ".")
err = ioutil.WriteFile(path.Join(testPath, file), []byte(content), 0644)
if err != nil {
return cleanup, err
}
cmd = exec.Command(gitPath, "add", file)
cmd.Dir = testPath
cmd.Output()

cmd = exec.Command(gitPath, "commit", "-m", content)
out, err = cmd.Output()
if err != nil {
return cleanup, err
}
cmd = exec.Command(gitPath, "config", "user.email", "much@email.com")
cmd.Dir = testPath
cmd.Output()

return func() {
exec.Command("rm", "-rf", testPath).Output()
out, err = cmd.Output()
if err != nil {
return cleanup, err
}
cmd = exec.Command(gitPath, "config", "user.name", "doge")
cmd.Dir = testPath
out, err = cmd.Output()
if err != nil {
return cleanup, err
}
cmd = exec.Command(gitPath, "commit", "-m", content)
cmd.Dir = testPath
out, err = cmd.Output()
return cleanup, err
}
9 changes: 4 additions & 5 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,17 @@ func (s *S) TestGetArchiveWhenCommandFails(c *gocheck.C) {
}

func (s *S) TestGetFileContentIntegration(c *gocheck.C) {
old_bare := bare
oldBare := bare
bare = "/tmp"
repo := "gandalf-test-repo"
file := "README"
content := "much WOW"
cleanUp := CreateTestRepository(bare, repo, file, content)

cleanUp, errCreate := CreateTestRepository(bare, repo, file, content)
defer func() {
cleanUp()
bare = old_bare
bare = oldBare
}()

c.Assert(errCreate, gocheck.IsNil)
contents, err := GetFileContents(repo, "master", file)
c.Assert(err, gocheck.IsNil)
c.Assert(string(contents), gocheck.Equals, content)
Expand Down

0 comments on commit 1c831f2

Please sign in to comment.