| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package git |
| 6 |
| 7 import ( |
| 8 "strings" |
| 9 "testing" |
| 10 |
| 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) |
| 13 |
| 14 func TestObjectFromRawWithID(t *testing.T) { |
| 15 Convey("ObjectFromRawWithID", t, func() { |
| 16 Convey("Should correctly produce a blob", func() { |
| 17 data := "howdee do, stranger" |
| 18 b, err := ObjectFromRaw(BlobType, []byte(data)) |
| 19 So(err, ShouldBeNil) |
| 20 So(b, ShouldHaveSameTypeAs, &Blob{}) |
| 21 blb := b.(*Blob) |
| 22 So(blb.ID().String(), ShouldEqual, "bca30a173ea717f56ba7
bc57bba79e0bb7cbfb89") |
| 23 So(blb.RawString(), ShouldEqual, data) |
| 24 }) |
| 25 |
| 26 Convey("Should correctly produce a tree", func() { |
| 27 Convey("Empty tree", func() { |
| 28 data := "" |
| 29 t, err := ObjectFromRaw(TreeType, []byte(data)) |
| 30 So(err, ShouldBeNil) |
| 31 So(t, ShouldHaveSameTypeAs, &Tree{}) |
| 32 tree := t.(*Tree) |
| 33 So(tree.ID().String(), ShouldEqual, "4b825dc642c
b6eb9a060e54bf8d69288fbee4904") |
| 34 So(tree.RawString(), ShouldEqual, data) |
| 35 So(tree.NumChildren(), ShouldEqual, 0) |
| 36 }) |
| 37 |
| 38 Convey("Interesting tree", func() { |
| 39 data := strings.Join([]string{ |
| 40 "160000 a commit\x00CTESTINGIDWHICHIS20B
", |
| 41 "100644 blob\x00BTESTINGIDWHICHIS20B", |
| 42 "40000 path\x00ATESTINGIDWHICHIS20B", |
| 43 }, "") |
| 44 t, err := ObjectFromRaw(TreeType, []byte(data)) |
| 45 So(err, ShouldBeNil) |
| 46 So(t, ShouldHaveSameTypeAs, &Tree{}) |
| 47 tree := t.(*Tree) |
| 48 So(tree.ID().String(), ShouldEqual, "5ff6938d327
8445e3aeece66970e2621659d44c7") |
| 49 So(tree.RawString(), ShouldEqual, data) |
| 50 So(tree.NumChildren(), ShouldEqual, 3) |
| 51 |
| 52 So(tree.GetChild("a commit").Object.Type(), Shou
ldEqual, CommitType) |
| 53 So(tree.GetChild("a commit").Object.ID().RawStri
ng(), ShouldEqual, "CTESTINGIDWHICHIS20B") |
| 54 |
| 55 So(tree.GetChild("blob").Object.Type(), ShouldEq
ual, BlobType) |
| 56 So(tree.GetChild("blob").Object.ID().RawString()
, ShouldEqual, "BTESTINGIDWHICHIS20B") |
| 57 |
| 58 So(tree.GetChild("path").Object.Type(), ShouldEq
ual, TreeType) |
| 59 So(tree.GetChild("path").Object.ID().RawString()
, ShouldEqual, "ATESTINGIDWHICHIS20B") |
| 60 }) |
| 61 }) |
| 62 |
| 63 Convey("Should correctly produce a commit", func() { |
| 64 data := strings.Join([]string{ |
| 65 "tree deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", |
| 66 "author wat <wat@chromium.org> 123456789 +0000", |
| 67 "committer lol <lol@chromium.org> 123456789 +000
0", |
| 68 "", |
| 69 "Cool message", |
| 70 }, "\n") |
| 71 c, err := ObjectFromRaw(CommitType, []byte(data)) |
| 72 So(err, ShouldBeNil) |
| 73 So(c, ShouldHaveSameTypeAs, &Commit{}) |
| 74 |
| 75 cmt := c.(*Commit) |
| 76 So(cmt.RawString(), ShouldEqual, data) |
| 77 So(cmt.ID().String(), ShouldEqual, "87fbd517aa7473876e2f
4bfccad35ce28e8b8de0") |
| 78 So(cmt.Author().Name, ShouldEqual, "wat") |
| 79 }) |
| 80 |
| 81 Convey("Anything else is bogus", func() { |
| 82 _, err := ObjectFromRaw(UnknownType, []byte(nil)) |
| 83 So(err, ShouldNotBeNil) |
| 84 _, err = ObjectFromRaw(TagType, []byte(nil)) |
| 85 So(err, ShouldNotBeNil) |
| 86 }) |
| 87 }) |
| 88 } |
| OLD | NEW |