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
|
package filesystem
import (
"gopkg.in/src-d/go-git.v4/core"
"gopkg.in/src-d/go-git.v4/fixtures"
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
. "gopkg.in/check.v1"
)
type FsSuite struct {
fixtures.Suite
}
var _ = Suite(&FsSuite{})
func (s *FsSuite) TestGetFromObjectFile(c *C) {
fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
expected := core.NewHash("f3dfe29d268303fc6e1bbce268605fc99573406e")
obj, err := o.Get(core.AnyObject, expected)
c.Assert(err, IsNil)
c.Assert(obj.Hash(), Equals, expected)
}
func (s *FsSuite) TestGetFromPackfile(c *C) {
fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
expected := core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
obj, err := o.Get(core.AnyObject, expected)
c.Assert(err, IsNil)
c.Assert(obj.Hash(), Equals, expected)
})
}
func (s *FsSuite) TestGetFromPackfileMultiplePackfiles(c *C) {
fs := fixtures.ByTag(".git").ByTag("multi-packfile").One().DotGit()
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
expected := core.NewHash("8d45a34641d73851e01d3754320b33bb5be3c4d3")
obj, err := o.getFromPackfile(expected)
c.Assert(err, IsNil)
c.Assert(obj.Hash(), Equals, expected)
expected = core.NewHash("e9cfa4c9ca160546efd7e8582ec77952a27b17db")
obj, err = o.getFromPackfile(expected)
c.Assert(err, IsNil)
c.Assert(obj.Hash(), Equals, expected)
}
func (s *FsSuite) TestIter(c *C) {
fixtures.ByTag(".git").ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
iter, err := o.Iter(core.AnyObject)
c.Assert(err, IsNil)
var count int32
err = iter.ForEach(func(o core.Object) error {
count++
return nil
})
c.Assert(err, IsNil)
c.Assert(count, Equals, f.ObjectsCount)
})
}
func (s *FsSuite) TestIterWithType(c *C) {
fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) {
fs := f.DotGit()
o, err := newObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
iter, err := o.Iter(core.CommitObject)
c.Assert(err, IsNil)
err = iter.ForEach(func(o core.Object) error {
c.Assert(o.Type(), Equals, core.CommitObject)
return nil
})
c.Assert(err, IsNil)
})
}
|