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

Commit

Permalink
Merge branch 'master' of https://github.com/tsuru/gandalf
Browse files Browse the repository at this point in the history
Conflicts:
	repository/repository_test.go
  • Loading branch information
heynemann committed Jul 3, 2014
2 parents 264fbe3 + 7df38e1 commit 4d89e70
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Danilo Bardusco <bardusco@gmail.com> <danilo@bardusco.com>
Flavia Missi <flaviamissi@gmail.com>
Flávio Ribeiro <flavio.ribeiro@corp.globo.com>
Francisco Souza <f@souza.cc> <fss@corp.globo.com>
Guilherme Souza <guivideojob@gmail.com>
Jay Graves <jaywgraves@gmail.com>
Michael <hfeeki@gmail.com>
Rodrigo Chacon <rochacon@gmail.com>
15 changes: 13 additions & 2 deletions repository/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ 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(), error) {
func CreateTestRepository(tmp_path string, repo string, file string, content string, folders ...string) (func(), error) {
testPath := path.Join(tmp_path, repo+".git")
cleanup := func() {
os.RemoveAll(testPath)
Expand All @@ -71,7 +71,18 @@ func CreateTestRepository(tmp_path string, repo string, file string, content str
if err != nil {
return cleanup, err
}
cmd = exec.Command(gitPath, "add", file)
for _, folder := range folders {
folderPath := path.Join(testPath, folder)
err = os.MkdirAll(folderPath, 0777)
if err != nil {
return cleanup, err
}
err = ioutil.WriteFile(path.Join(folderPath, file), []byte(content), 0644)
if err != nil {
return cleanup, err
}
}
cmd = exec.Command(gitPath, "add", ".")
cmd.Dir = testPath
err = cmd.Run()
if err != nil {
Expand Down
78 changes: 74 additions & 4 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func (s *S) TestGetFileContentIntegration(c *gocheck.C) {
c.Assert(string(contents), gocheck.Equals, content)
}

func (s *S) TestGetFileContentIntegrationWhenInvalidRepo(c *gocheck.C) {
func (s *S) TestGetFileContentWhenRefIsInvalid(c *gocheck.C) {
oldBare := bare
bare = "/tmp"
repo := "gandalf-test-repo"
Expand All @@ -550,9 +550,79 @@ func (s *S) TestGetFileContentIntegrationWhenInvalidRepo(c *gocheck.C) {
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
_, err := GetFileContents("invalid-repo", "master", file)
expected := "Error when trying to obtain file README on ref master of repository invalid-repo (Repository does not exist)."
c.Assert(err.Error(), gocheck.Equals, expected)
_, err := GetFileContents(repo, "MuchMissing", file)
c.Assert(err, gocheck.ErrorMatches, "^Error when trying to obtain file README on ref MuchMissing of repository gandalf-test-repo \\(exit status 128\\)\\.$")
}

func (s *S) TestGetFileContentWhenFileIsInvalid(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)

_, err := GetFileContents(repo, "master", "Such file")
c.Assert(err, gocheck.ErrorMatches, "^Error when trying to obtain file Such file on ref master of repository gandalf-test-repo \\(exit status 128\\)\\.$")
}

func (s *S) TestGetTreeIntegration(c *gocheck.C) {
oldBare := bare
bare = "/tmp"
repo := "gandalf-test-repo"
file := "README"
content := "much WOW"
cleanUp, errCreate := CreateTestRepository(bare, repo, file, content, []string{"such", "folder", "much", "magic"}...)
defer func() {
cleanUp()
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
tree, err := GetTree(repo, "master", "much/README")
c.Assert(err, gocheck.IsNil)
c.Assert(tree[0]["path"], gocheck.Equals, "much/README")
c.Assert(tree[0]["rawPath"], gocheck.Equals, "much/README")
}

func (s *S) TestGetTreeIntegrationWithEscapedFileName(c *gocheck.C) {
oldBare := bare
bare = "/tmp"
repo := "gandalf-test-repo"
file := "such\tREADME"
content := "much WOW"
cleanUp, errCreate := CreateTestRepository(bare, repo, file, content, []string{"such", "folder", "much", "magic"}...)
defer func() {
cleanUp()
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
tree, err := GetTree(repo, "master", "much/such\tREADME")
c.Assert(err, gocheck.IsNil)
c.Assert(tree[0]["path"], gocheck.Equals, "much/such\\tREADME")
c.Assert(tree[0]["rawPath"], gocheck.Equals, "\"much/such\\tREADME\"")
}

func (s *S) TestGetTreeIntegrationWithFileNameWithSpace(c *gocheck.C) {
oldBare := bare
bare = "/tmp"
repo := "gandalf-test-repo"
file := "much README"
content := "much WOW"
cleanUp, errCreate := CreateTestRepository(bare, repo, file, content, []string{"such", "folder", "much", "magic"}...)
defer func() {
cleanUp()
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
tree, err := GetTree(repo, "master", "much/much README")
c.Assert(err, gocheck.IsNil)
c.Assert(tree[0]["path"], gocheck.Equals, "much/much README")
c.Assert(tree[0]["rawPath"], gocheck.Equals, "much/much README")
}

func (s *S) TestGetArchiveIntegrationWhenZip(c *gocheck.C) {
Expand Down

0 comments on commit 4d89e70

Please sign in to comment.