1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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))
}
}
|