diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-24 22:40:30 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-25 00:38:51 -0800 |
commit | 0d999e1db6cd8736ab697de8ce848fa3a5274b9f (patch) | |
tree | 6107f49405bb605793f1bcd7ef4961ceadcb11e9 /objects_test.go | |
parent | 07ca1ac7f3058ea6d3274a01973541fb84782f5e (diff) | |
download | go-git-0d999e1db6cd8736ab697de8ce848fa3a5274b9f.tar.gz |
Refactor to use core.ObjectReader and core.ObjectWriter
* New function signatures provide the necessary interface to stream data from disk when using filesystem-based storage in the future
* New function signatures provide proper error handling
* ObjectReader and ObjectWriter interfaces added to avoid future refactoring, currently are type aliases for io.ReadCloser and io.WriteCloser respectively
* Object.Reader now returns (ObjectReader, error)
* Object.Writer now returns (ObjectWriter, error)
* File.Contents now returns (string, error)
* File.Lines now returns ([]string, error)
* Blob.Reader now returns (core.ObjectReader, error)
* Added internal close helper function for deferred calls to Close that need to check the return value
Diffstat (limited to 'objects_test.go')
-rw-r--r-- | objects_test.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/objects_test.go b/objects_test.go index 10b9661..6826957 100644 --- a/objects_test.go +++ b/objects_test.go @@ -67,7 +67,10 @@ func (s *ObjectsSuite) TestParseTree(c *C) { for f, err := iter.Next(); err == nil; f, err = iter.Next() { count++ if f.Name == "go/example.go" { - content, _ := ioutil.ReadAll(f.Reader()) + reader, err := f.Reader() + c.Assert(err, IsNil) + defer func() { c.Assert(reader.Close(), IsNil) }() + content, _ := ioutil.ReadAll(reader) c.Assert(content, HasLen, 2780) } } @@ -79,7 +82,12 @@ func (s *ObjectsSuite) TestBlobHash(c *C) { o := &memory.Object{} o.SetType(core.BlobObject) o.SetSize(3) - o.Writer().Write([]byte{'F', 'O', 'O'}) + + writer, err := o.Writer() + c.Assert(err, IsNil) + defer func() { c.Assert(writer.Close(), IsNil) }() + + writer.Write([]byte{'F', 'O', 'O'}) blob := &Blob{} c.Assert(blob.Decode(o), IsNil) @@ -87,7 +95,11 @@ func (s *ObjectsSuite) TestBlobHash(c *C) { c.Assert(blob.Size, Equals, int64(3)) c.Assert(blob.Hash.String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") - data, err := ioutil.ReadAll(blob.Reader()) + reader, err := blob.Reader() + c.Assert(err, IsNil) + defer func() { c.Assert(reader.Close(), IsNil) }() + + data, err := ioutil.ReadAll(reader) c.Assert(err, IsNil) c.Assert(string(data), Equals, "FOO") } |