| Index: go/src/infra/libs/git/object_test.go
|
| diff --git a/go/src/infra/libs/git/object_test.go b/go/src/infra/libs/git/object_test.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ef42541c0a72e438620347ada32091556caf0525
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/git/object_test.go
|
| @@ -0,0 +1,88 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package git
|
| +
|
| +import (
|
| + "strings"
|
| + "testing"
|
| +
|
| + . "github.com/smartystreets/goconvey/convey"
|
| +)
|
| +
|
| +func TestObjectFromRawWithID(t *testing.T) {
|
| + Convey("ObjectFromRawWithID", t, func() {
|
| + Convey("Should correctly produce a blob", func() {
|
| + data := "howdee do, stranger"
|
| + b, err := ObjectFromRaw(BlobType, []byte(data))
|
| + So(err, ShouldBeNil)
|
| + So(b, ShouldHaveSameTypeAs, &Blob{})
|
| + blb := b.(*Blob)
|
| + So(blb.ID().String(), ShouldEqual, "bca30a173ea717f56ba7bc57bba79e0bb7cbfb89")
|
| + So(blb.RawString(), ShouldEqual, data)
|
| + })
|
| +
|
| + Convey("Should correctly produce a tree", func() {
|
| + Convey("Empty tree", func() {
|
| + data := ""
|
| + t, err := ObjectFromRaw(TreeType, []byte(data))
|
| + So(err, ShouldBeNil)
|
| + So(t, ShouldHaveSameTypeAs, &Tree{})
|
| + tree := t.(*Tree)
|
| + So(tree.ID().String(), ShouldEqual, "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
|
| + So(tree.RawString(), ShouldEqual, data)
|
| + So(tree.NumChildren(), ShouldEqual, 0)
|
| + })
|
| +
|
| + Convey("Interesting tree", func() {
|
| + data := strings.Join([]string{
|
| + "160000 a commit\x00CTESTINGIDWHICHIS20B",
|
| + "100644 blob\x00BTESTINGIDWHICHIS20B",
|
| + "40000 path\x00ATESTINGIDWHICHIS20B",
|
| + }, "")
|
| + t, err := ObjectFromRaw(TreeType, []byte(data))
|
| + So(err, ShouldBeNil)
|
| + So(t, ShouldHaveSameTypeAs, &Tree{})
|
| + tree := t.(*Tree)
|
| + So(tree.ID().String(), ShouldEqual, "5ff6938d3278445e3aeece66970e2621659d44c7")
|
| + So(tree.RawString(), ShouldEqual, data)
|
| + So(tree.NumChildren(), ShouldEqual, 3)
|
| +
|
| + So(tree.GetChild("a commit").Object.Type(), ShouldEqual, CommitType)
|
| + So(tree.GetChild("a commit").Object.ID().RawString(), ShouldEqual, "CTESTINGIDWHICHIS20B")
|
| +
|
| + So(tree.GetChild("blob").Object.Type(), ShouldEqual, BlobType)
|
| + So(tree.GetChild("blob").Object.ID().RawString(), ShouldEqual, "BTESTINGIDWHICHIS20B")
|
| +
|
| + So(tree.GetChild("path").Object.Type(), ShouldEqual, TreeType)
|
| + So(tree.GetChild("path").Object.ID().RawString(), ShouldEqual, "ATESTINGIDWHICHIS20B")
|
| + })
|
| + })
|
| +
|
| + Convey("Should correctly produce a commit", func() {
|
| + data := strings.Join([]string{
|
| + "tree deadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
|
| + "author wat <wat@chromium.org> 123456789 +0000",
|
| + "committer lol <lol@chromium.org> 123456789 +0000",
|
| + "",
|
| + "Cool message",
|
| + }, "\n")
|
| + c, err := ObjectFromRaw(CommitType, []byte(data))
|
| + So(err, ShouldBeNil)
|
| + So(c, ShouldHaveSameTypeAs, &Commit{})
|
| +
|
| + cmt := c.(*Commit)
|
| + So(cmt.RawString(), ShouldEqual, data)
|
| + So(cmt.ID().String(), ShouldEqual, "87fbd517aa7473876e2f4bfccad35ce28e8b8de0")
|
| + So(cmt.Author().Name, ShouldEqual, "wat")
|
| + })
|
| +
|
| + Convey("Anything else is bogus", func() {
|
| + _, err := ObjectFromRaw(UnknownType, []byte(nil))
|
| + So(err, ShouldNotBeNil)
|
| + _, err = ObjectFromRaw(TagType, []byte(nil))
|
| + So(err, ShouldNotBeNil)
|
| + })
|
| + })
|
| +}
|
|
|