diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-02-17 00:24:31 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-02-17 11:46:00 +0100 |
commit | a964e32d92c53a47ce7c46d589a18c62133b8c50 (patch) | |
tree | 4c094cd6afb95cb2832f866b9411276418435819 /storage/memory/object_test.go | |
parent | 1ac00554c3b5f88d2ddc2e28e7cfcdcad9d9f4bb (diff) | |
download | go-git-a964e32d92c53a47ce7c46d589a18c62133b8c50.tar.gz |
storages: memory object
Diffstat (limited to 'storage/memory/object_test.go')
-rw-r--r-- | storage/memory/object_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/storage/memory/object_test.go b/storage/memory/object_test.go new file mode 100644 index 0000000..b606eb2 --- /dev/null +++ b/storage/memory/object_test.go @@ -0,0 +1,67 @@ +package memory + +import ( + "io/ioutil" + "testing" + + . "gopkg.in/check.v1" + "gopkg.in/src-d/go-git.v2/core" +) + +func Test(t *testing.T) { TestingT(t) } + +type ObjectSuite struct{} + +var _ = Suite(&ObjectSuite{}) + +func (s *ObjectSuite) TestHash(c *C) { + o := &Object{} + o.SetType(core.BlobObject) + o.SetSize(14) + + _, err := o.Write([]byte("Hello, World!\n")) + c.Assert(err, IsNil) + + c.Assert(o.Hash().String(), Equals, "8ab686eafeb1f44702738c8b0f24f2567c36da6d") + + o.SetType(core.CommitObject) + c.Assert(o.Hash().String(), Equals, "8ab686eafeb1f44702738c8b0f24f2567c36da6d") +} + +func (s *ObjectSuite) TestHashNotFilled(c *C) { + o := &Object{} + o.SetType(core.BlobObject) + o.SetSize(14) + + c.Assert(o.Hash(), Equals, core.ZeroHash) +} + +func (s *ObjectSuite) TestType(c *C) { + o := &Object{} + o.SetType(core.BlobObject) + c.Assert(o.Type(), Equals, core.BlobObject) +} + +func (s *ObjectSuite) TestSize(c *C) { + o := &Object{} + o.SetSize(42) + c.Assert(o.Size(), Equals, int64(42)) +} + +func (s *ObjectSuite) TestReader(c *C) { + o := &Object{content: []byte("foo")} + + b, err := ioutil.ReadAll(o.Reader()) + c.Assert(err, IsNil) + c.Assert(b, DeepEquals, []byte("foo")) +} + +func (s *ObjectSuite) TestWriter(c *C) { + o := &Object{} + + n, err := o.Writer().Write([]byte("foo")) + c.Assert(err, IsNil) + c.Assert(n, Equals, 3) + + c.Assert(o.content, DeepEquals, []byte("foo")) +} |