diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-08 23:46:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-08 23:46:38 +0100 |
commit | ac095bb12c4d29722b60ba9f20590fa7cfa6bc7d (patch) | |
tree | 223f36f336ba3414b1e45cac8af6c4744a5d7ef6 /plumbing/memory_test.go | |
parent | e523701393598f4fa241dd407af9ff8925507a1a (diff) | |
download | go-git-ac095bb12c4d29722b60ba9f20590fa7cfa6bc7d.tar.gz |
new plumbing package (#118)
* plumbing: now core was renamed to core, and formats and clients moved inside
Diffstat (limited to 'plumbing/memory_test.go')
-rw-r--r-- | plumbing/memory_test.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/plumbing/memory_test.go b/plumbing/memory_test.go new file mode 100644 index 0000000..879ed37 --- /dev/null +++ b/plumbing/memory_test.go @@ -0,0 +1,71 @@ +package plumbing + +import ( + "io/ioutil" + + . "gopkg.in/check.v1" +) + +type MemoryObjectSuite struct{} + +var _ = Suite(&MemoryObjectSuite{}) + +func (s *MemoryObjectSuite) TestHash(c *C) { + o := &MemoryObject{} + o.SetType(BlobObject) + o.SetSize(14) + + _, err := o.Write([]byte("Hello, World!\n")) + c.Assert(err, IsNil) + + c.Assert(o.Hash().String(), Equals, "8ab686eafeb1f44702738c8b0f24f2567c36da6d") + + o.SetType(CommitObject) + c.Assert(o.Hash().String(), Equals, "8ab686eafeb1f44702738c8b0f24f2567c36da6d") +} + +func (s *MemoryObjectSuite) TestHashNotFilled(c *C) { + o := &MemoryObject{} + o.SetType(BlobObject) + o.SetSize(14) + + c.Assert(o.Hash(), Equals, ZeroHash) +} + +func (s *MemoryObjectSuite) TestType(c *C) { + o := &MemoryObject{} + o.SetType(BlobObject) + c.Assert(o.Type(), Equals, BlobObject) +} + +func (s *MemoryObjectSuite) TestSize(c *C) { + o := &MemoryObject{} + o.SetSize(42) + c.Assert(o.Size(), Equals, int64(42)) +} + +func (s *MemoryObjectSuite) TestReader(c *C) { + o := &MemoryObject{cont: []byte("foo")} + + reader, err := o.Reader() + c.Assert(err, IsNil) + defer func() { c.Assert(reader.Close(), IsNil) }() + + b, err := ioutil.ReadAll(reader) + c.Assert(err, IsNil) + c.Assert(b, DeepEquals, []byte("foo")) +} + +func (s *MemoryObjectSuite) TestWriter(c *C) { + o := &MemoryObject{} + + writer, err := o.Writer() + c.Assert(err, IsNil) + defer func() { c.Assert(writer.Close(), IsNil) }() + + n, err := writer.Write([]byte("foo")) + c.Assert(err, IsNil) + c.Assert(n, Equals, 3) + + c.Assert(o.cont, DeepEquals, []byte("foo")) +} |