aboutsummaryrefslogtreecommitdiffstats
path: root/common_test.go
diff options
context:
space:
mode:
authorAlberto Cortés <alberto@sourced.tech>2015-11-27 12:39:34 +0100
committerAlberto Cortés <alberto@sourced.tech>2015-12-04 09:48:41 +0100
commit48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc (patch)
treed96d8dfe4c8e4e18f19f2f50d67befc4d9a88d57 /common_test.go
parentd643cea1e8a6d618b2eddfdbed086c7bdf208658 (diff)
downloadgo-git-48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc.tar.gz
fix PR#7 comments
Diffstat (limited to 'common_test.go')
-rw-r--r--common_test.go92
1 files changed, 4 insertions, 88 deletions
diff --git a/common_test.go b/common_test.go
index 0695d5f..4c48419 100644
--- a/common_test.go
+++ b/common_test.go
@@ -5,10 +5,10 @@ import (
"os"
"testing"
- . "gopkg.in/check.v1"
"gopkg.in/src-d/go-git.v2/clients/common"
"gopkg.in/src-d/go-git.v2/core"
- "gopkg.in/src-d/go-git.v2/formats/packfile"
+
+ . "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
@@ -44,39 +44,10 @@ func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadC
return r, nil
}
-type SuiteCommon struct {
- repos map[string]*Repository
-}
+type SuiteCommon struct{}
var _ = Suite(&SuiteCommon{})
-var fixtureRepos = [...]struct {
- url string
- packfile string
-}{
- {"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"},
-}
-
-// create the repositories of the fixtures
-func (s *SuiteCommon) SetUpSuite(c *C) {
- s.repos = make(map[string]*Repository, 0)
- for _, fixRepo := range fixtureRepos {
- s.repos[fixRepo.url] = NewPlainRepository()
-
- d, err := os.Open(fixRepo.packfile)
- defer func() {
- c.Assert(d.Close(), IsNil)
- }()
- c.Assert(err, IsNil)
-
- r := packfile.NewReader(d)
- r.Format = packfile.OFSDeltaFormat // TODO: how to know the format of a pack file ahead of time?
-
- _, err = r.Read(s.repos[fixRepo.url].Storage)
- c.Assert(err, IsNil)
- }
-}
-
var countLinesTests = [...]struct {
i string // the string we want to count lines from
e int // the expected number of lines in i
@@ -88,6 +59,7 @@ var countLinesTests = [...]struct {
{"a\nb\n", 2},
{"a\nb\nc", 3},
{"a\nb\nc\n", 3},
+ {"a\n\n\nb\n", 4},
{"first line\n\tsecond line\nthird line\n", 3},
}
@@ -97,59 +69,3 @@ func (s *SuiteCommon) TestCountLines(c *C) {
c.Assert(o, Equals, t.e, Commentf("subtest %d, input=%q", i, t.i))
}
}
-
-var findFileTests = []struct {
- repo string // the repo name as in localRepos
- commit string // the commit to search for the file
- path string // the path of the file to find
- blobHash string // expected hash of the returned file
- found bool // expected found value
-}{
- // use git ls-tree commit to get the hash of the blobs
- {"https://github.com/tyba/git-fixture.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", "not-found",
- "", false},
- {"https://github.com/tyba/git-fixture.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", ".gitignore",
- "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88", true},
- {"https://github.com/tyba/git-fixture.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", "LICENSE",
- "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f", true},
-
- {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "not-found",
- "", false},
- {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", ".gitignore",
- "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88", true},
- {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "binary.jpg",
- "d5c0f4ab811897cadf03aec358ae60d21f91c50d", true},
- {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "LICENSE",
- "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f", true},
-
- {"https://github.com/tyba/git-fixture.git", "35e85108805c84807bc66a02d91535e1e24b38b9", "binary.jpg",
- "d5c0f4ab811897cadf03aec358ae60d21f91c50d", true},
- {"https://github.com/tyba/git-fixture.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", "binary.jpg",
- "", false},
-
- {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG",
- "d3ff53e0564a9f87d8e84b6e28e5060e517008aa", true},
- {"https://github.com/tyba/git-fixture.git", "1669dce138d9b841a518c64b10914d88f5e488ea", "CHANGELOG",
- "d3ff53e0564a9f87d8e84b6e28e5060e517008aa", true},
- {"https://github.com/tyba/git-fixture.git", "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", "CHANGELOG",
- "d3ff53e0564a9f87d8e84b6e28e5060e517008aa", true},
- {"https://github.com/tyba/git-fixture.git", "35e85108805c84807bc66a02d91535e1e24b38b9", "CHANGELOG",
- "d3ff53e0564a9f87d8e84b6e28e5060e517008aa", false},
- {"https://github.com/tyba/git-fixture.git", "b8e471f58bcbca63b07bda20e428190409c2db47", "CHANGELOG",
- "d3ff53e0564a9f87d8e84b6e28e5060e517008aa", true},
- {"https://github.com/tyba/git-fixture.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", "CHANGELOG",
- "d3ff53e0564a9f87d8e84b6e28e5060e517008aa", false},
-}
-
-func (s *SuiteCommon) TestFindFile(c *C) {
- for i, t := range findFileTests {
- commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
- c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
-
- file, found := FindFile(t.path, commit)
- c.Assert(found, Equals, t.found, Commentf("subtest %d, path=%s, commit=%s", i, t.path, t.commit))
- if found {
- c.Assert(file.Hash.String(), Equals, t.blobHash, Commentf("subtest %d, commit=%s, path=%s", i, t.commit, t.path))
- }
- }
-}