aboutsummaryrefslogtreecommitdiffstats
path: root/file_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 /file_test.go
parentd643cea1e8a6d618b2eddfdbed086c7bdf208658 (diff)
downloadgo-git-48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc.tar.gz
fix PR#7 comments
Diffstat (limited to 'file_test.go')
-rw-r--r--file_test.go133
1 files changed, 133 insertions, 0 deletions
diff --git a/file_test.go b/file_test.go
new file mode 100644
index 0000000..8c22bb3
--- /dev/null
+++ b/file_test.go
@@ -0,0 +1,133 @@
+package git
+
+import (
+ "os"
+
+ "gopkg.in/src-d/go-git.v2/core"
+ "gopkg.in/src-d/go-git.v2/formats/packfile"
+
+ . "gopkg.in/check.v1"
+)
+
+type SuiteFile struct {
+ repos map[string]*Repository
+}
+
+var _ = Suite(&SuiteFile{})
+
+// create the repositories of the fixtures
+func (s *SuiteFile) SetUpSuite(c *C) {
+ fixtureRepos := [...]struct {
+ url string
+ packfile string
+ }{
+ {"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"},
+ }
+ s.repos = make(map[string]*Repository, 0)
+ for _, fixRepo := range fixtureRepos {
+ s.repos[fixRepo.url] = NewPlainRepository()
+
+ d, err := os.Open(fixRepo.packfile)
+ c.Assert(err, IsNil)
+
+ r := packfile.NewReader(d)
+ r.Format = packfile.OFSDeltaFormat
+
+ _, err = r.Read(s.repos[fixRepo.url].Storage)
+ c.Assert(err, IsNil)
+
+ c.Assert(d.Close(), IsNil)
+ }
+}
+
+var contentsTests = []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
+ contents string // expected contents of the file
+}{
+ {
+ "https://github.com/tyba/git-fixture.git",
+ "b029517f6300c2da0f4b651b8642506cd6aaf45d",
+ ".gitignore",
+ `*.class
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+`,
+ },
+ {
+ "https://github.com/tyba/git-fixture.git",
+ "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
+ "CHANGELOG",
+ `Initial changelog
+`,
+ },
+}
+
+func (s *SuiteFile) TestContents(c *C) {
+ for i, t := range contentsTests {
+ 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, err := commit.File(t.path)
+ c.Assert(err, IsNil)
+ c.Assert(file.Contents(), Equals, t.contents, Commentf(
+ "subtest %d: commit=%s, path=%s", i, t.commit, t.path))
+ }
+}
+
+var linesTests = []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
+ lines []string // expected lines in the file
+}{
+ {
+ "https://github.com/tyba/git-fixture.git",
+ "b029517f6300c2da0f4b651b8642506cd6aaf45d",
+ ".gitignore",
+ []string{
+ "*.class",
+ "",
+ "# Mobile Tools for Java (J2ME)",
+ ".mtj.tmp/",
+ "",
+ "# Package Files #",
+ "*.jar",
+ "*.war",
+ "*.ear",
+ "",
+ "# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml",
+ "hs_err_pid*",
+ },
+ },
+ {
+ "https://github.com/tyba/git-fixture.git",
+ "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
+ "CHANGELOG",
+ []string{
+ "Initial changelog",
+ },
+ },
+}
+
+func (s *SuiteFile) TestLines(c *C) {
+ for i, t := range linesTests {
+ 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, err := commit.File(t.path)
+ c.Assert(err, IsNil)
+ c.Assert(file.Lines(), DeepEquals, t.lines, Commentf(
+ "subtest %d: commit=%s, path=%s", i, t.commit, t.path))
+ }
+}