From 688e802814f791a8723874dc88437bd8d140e103 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 26 Oct 2015 01:22:54 +0100 Subject: objects: using readers from internal.Object --- objects_test.go | 58 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'objects_test.go') diff --git a/objects_test.go b/objects_test.go index 53da5f0..ec39d44 100644 --- a/objects_test.go +++ b/objects_test.go @@ -2,9 +2,11 @@ package git import ( "encoding/base64" + "io/ioutil" "time" . "gopkg.in/check.v1" + "gopkg.in/src-d/go-git.v2/internal" ) type ObjectsSuite struct{} @@ -13,11 +15,17 @@ var _ = Suite(&ObjectsSuite{}) var CommitFixture = "dHJlZSBjMmQzMGZhOGVmMjg4NjE4ZjY1ZjZlZWQ2ZTE2OGUwZDUxNDg4NmY0CnBhcmVudCBiMDI5NTE3ZjYzMDBjMmRhMGY0YjY1MWI4NjQyNTA2Y2Q2YWFmNDVkCnBhcmVudCBiOGU0NzFmNThiY2JjYTYzYjA3YmRhMjBlNDI4MTkwNDA5YzJkYjQ3CmF1dGhvciBNw6F4aW1vIEN1YWRyb3MgPG1jdWFkcm9zQGdtYWlsLmNvbT4gMTQyNzgwMjQzNCArMDIwMApjb21taXR0ZXIgTcOheGltbyBDdWFkcm9zIDxtY3VhZHJvc0BnbWFpbC5jb20+IDE0Mjc4MDI0MzQgKzAyMDAKCk1lcmdlIHB1bGwgcmVxdWVzdCAjMSBmcm9tIGRyaXBvbGxlcy9mZWF0dXJlCgpDcmVhdGluZyBjaGFuZ2Vsb2c=" -func (s *ObjectsSuite) TestParseCommit(c *C) { +func (s *ObjectsSuite) TestNewCommit(c *C) { data, _ := base64.StdEncoding.DecodeString(CommitFixture) - commit, err := ParseCommit(data) - c.Assert(err, IsNil) + o := &internal.RAWObject{} + o.SetType(internal.CommitObject) + o.Writer().Write(data) + + commit := &Commit{} + c.Assert(commit.Decode(o), IsNil) + + c.Assert(commit.Hash.String(), Equals, "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69") c.Assert(commit.Tree.String(), Equals, "c2d30fa8ef288618f65f6eed6e168e0d514886f4") c.Assert(commit.Parents, HasLen, 2) c.Assert(commit.Parents[0].String(), Equals, "b029517f6300c2da0f4b651b8642506cd6aaf45d") @@ -26,43 +34,43 @@ func (s *ObjectsSuite) TestParseCommit(c *C) { c.Assert(commit.Author.Name, Equals, "Máximo Cuadros") c.Assert(commit.Author.When.Unix(), Equals, int64(1427802434)) c.Assert(commit.Committer.Email, Equals, "mcuadros@gmail.com") - c.Assert(commit.Message, Equals, "Merge pull request #1 from dripolles/feature\n\nCreating changelog") -} - -func (s *ObjectsSuite) TestCommitHash(c *C) { - data, _ := base64.StdEncoding.DecodeString(CommitFixture) - commit, err := ParseCommit(data) - - c.Assert(err, IsNil) - c.Assert(commit.Hash().String(), Equals, "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69") + c.Assert(commit.Message, Equals, "Merge pull request #1 from dripolles/feature\n\nCreating changelog\n") } var TreeFixture = "MTAwNjQ0IC5naXRpZ25vcmUAMoWKrTw4PtH/Cg+b3yMdVKAMnogxMDA2NDQgQ0hBTkdFTE9HANP/U+BWSp+H2OhLbijlBg5RcAiqMTAwNjQ0IExJQ0VOU0UAwZK9aiTqGrAdeGhuQXyL3Hw9GX8xMDA2NDQgYmluYXJ5LmpwZwDVwPSrgRiXyt8DrsNYrmDSH5HFDTQwMDAwIGdvAKOXcadlH5f69ccuCCJNhX/DUTPbNDAwMDAganNvbgBah35qkGonQ61uRdmcF5NkKq+O2jQwMDAwIHBocABYavVn0Ltedx5JvdlDT14Pt20l+jQwMDAwIHZlbmRvcgDPSqOziXT7fYHzZ8CDD3141lq4aw==" func (s *ObjectsSuite) TestParseTree(c *C) { data, _ := base64.StdEncoding.DecodeString(TreeFixture) - tree, err := ParseTree(data) - c.Assert(err, IsNil) + + o := &internal.RAWObject{} + o.SetType(internal.TreeObject) + o.SetSize(int64(len(data))) + o.Writer().Write(data) + + tree := &Tree{} + c.Assert(tree.Decode(o), IsNil) c.Assert(tree.Entries, HasLen, 8) c.Assert(tree.Entries[0].Name, Equals, ".gitignore") + c.Assert(tree.Entries[0].Mode.String(), Equals, "-rw-r--r--") c.Assert(tree.Entries[0].Hash.String(), Equals, "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88") } -func (s *ObjectsSuite) TestTreeHash(c *C) { - data, _ := base64.StdEncoding.DecodeString(TreeFixture) - tree, err := ParseTree(data) +func (s *ObjectsSuite) TestBlobHash(c *C) { + o := &internal.RAWObject{} + o.SetType(internal.BlobObject) + o.SetSize(3) + o.Writer().Write([]byte{'F', 'O', 'O'}) - c.Assert(err, IsNil) - c.Assert(tree.Hash().String(), Equals, "a8d315b2b1c615d43042c3a62402b8a54288cf5c") -} + blob := &Blob{} + c.Assert(blob.Decode(o), IsNil) -func (s *ObjectsSuite) TestBlobHash(c *C) { - blob, err := ParseBlob([]byte{'F', 'O', 'O'}) - c.Assert(err, IsNil) + c.Assert(blob.Size, Equals, int64(3)) + c.Assert(blob.Hash.String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") - c.Assert(blob.Len, Equals, 3) - c.Assert(blob.Hash().String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") + data, err := ioutil.ReadAll(blob.Reader()) + c.Assert(err, IsNil) + c.Assert(string(data), Equals, "FOO") } func (s *ObjectsSuite) TestParseSignature(c *C) { -- cgit