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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
package memory
import (
"io"
"testing"
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-git.v4/core"
)
func Test(t *testing.T) { TestingT(t) }
type StorageSuite struct{}
var _ = Suite(&StorageSuite{})
func (s *StorageSuite) TestStorageObjectStorage(c *C) {
storage := NewStorage()
o := storage.ObjectStorage()
e := storage.ObjectStorage()
c.Assert(o == e, Equals, true)
}
func (s *StorageSuite) TestStorageReferenceStorage(c *C) {
storage := NewStorage()
o := storage.ReferenceStorage()
e := storage.ReferenceStorage()
c.Assert(o == e, Equals, true)
}
func (s *StorageSuite) TestObjectStorageSetAndGet(c *C) {
storage := NewStorage()
os := storage.ObjectStorage()
commit := &core.MemoryObject{}
commit.SetType(core.CommitObject)
h, err := os.Set(commit)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, "dcf5b16e76cce7425d0beaef62d79a7d10fce1f5")
e, err := os.Get(h)
c.Assert(commit == e, Equals, true)
tree := &core.MemoryObject{}
tree.SetType(core.TreeObject)
h, err = os.Set(tree)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
e, err = os.Get(h)
c.Assert(tree == e, Equals, true)
blob := &core.MemoryObject{}
blob.SetType(core.BlobObject)
h, err = os.Set(blob)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
e, err = os.Get(h)
c.Assert(blob == e, Equals, true)
tag := &core.MemoryObject{}
tag.SetType(core.TagObject)
h, err = os.Set(tag)
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, "d994c6bb648123a17e8f70a966857c546b2a6f94")
e, err = os.Get(h)
c.Assert(tag == e, Equals, true)
}
func (s *StorageSuite) TestObjectStorageIter(c *C) {
commit := &core.MemoryObject{}
commit.SetType(core.CommitObject)
tree := &core.MemoryObject{}
tree.SetType(core.TreeObject)
blob := &core.MemoryObject{}
blob.SetType(core.BlobObject)
tag := &core.MemoryObject{}
tag.SetType(core.TagObject)
storage := NewStorage()
os := storage.ObjectStorage()
os.Set(commit)
os.Set(tree)
os.Set(blob)
os.Set(tag)
i, err := os.Iter(core.CommitObject)
c.Assert(err, IsNil)
e, err := i.Next()
c.Assert(err, IsNil)
c.Assert(commit == e, Equals, true)
i, err = os.Iter(core.TreeObject)
c.Assert(err, IsNil)
e, err = i.Next()
c.Assert(err, IsNil)
c.Assert(tree == e, Equals, true)
i, err = os.Iter(core.BlobObject)
c.Assert(err, IsNil)
e, err = i.Next()
c.Assert(err, IsNil)
c.Assert(blob == e, Equals, true)
i, err = os.Iter(core.TagObject)
c.Assert(err, IsNil)
e, err = i.Next()
c.Assert(err, IsNil)
c.Assert(tag == e, Equals, true)
e, err = i.Next()
c.Assert(e, IsNil)
c.Assert(err, Equals, io.EOF)
}
func (s *StorageSuite) TestReferenceStorageSetAndGet(c *C) {
storage := NewStorage()
rs := storage.ReferenceStorage()
err := rs.Set(core.NewReferenceFromStrings("foo", "bc9968d75e48de59f0870ffb71f5e160bbbdcf52"))
c.Assert(err, IsNil)
err = rs.Set(core.NewReferenceFromStrings("bar", "482e0eada5de4039e6f216b45b3c9b683b83bfa"))
c.Assert(err, IsNil)
e, err := rs.Get(core.ReferenceName("foo"))
c.Assert(err, IsNil)
c.Assert(e.Hash().String(), Equals, "bc9968d75e48de59f0870ffb71f5e160bbbdcf52")
}
func (s *StorageSuite) TestReferenceStorageIter(c *C) {
storage := NewStorage()
rs := storage.ReferenceStorage()
err := rs.Set(core.NewReferenceFromStrings("foo", "bc9968d75e48de59f0870ffb71f5e160bbbdcf52"))
c.Assert(err, IsNil)
i, err := rs.Iter()
c.Assert(err, IsNil)
e, err := i.Next()
c.Assert(err, IsNil)
c.Assert(e.Hash().String(), Equals, "bc9968d75e48de59f0870ffb71f5e160bbbdcf52")
e, err = i.Next()
c.Assert(e, IsNil)
c.Assert(err, Equals, io.EOF)
}
|