| 10 | ) |
| 11 | |
| 12 | func TestDecodeCommitSHA256ObjectIDs(t *testing.T) { |
| 13 | const ( |
| 14 | treeID = "151c11736080ee7fe882040a334ec2ae4a815deca7a3d63374500e107dbcda09" |
| 15 | parentID = "36561e87343747f0bc493eeeb04d910e5382c3419c42d412687e2aac5e4c40a1" |
| 16 | raw = "tree " + treeID + "\n" + |
| 17 | "parent " + parentID + "\n" + |
| 18 | "author Foo <foo@example.local> 1427802494 +0200\n" + |
| 19 | "committer Foo <foo@example.local> 1427802494 +0200\n\n" + |
| 20 | "msg\n" |
| 21 | ) |
| 22 | |
| 23 | obj := &plumbing.MemoryObject{} |
| 24 | obj.SetType(plumbing.CommitObject) |
| 25 | if _, err := obj.Write([]byte(raw)); err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | |
| 29 | commit := &Commit{} |
| 30 | if err := commit.Decode(obj); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | |
| 34 | if got := commit.TreeHash.String(); got != treeID { |
| 35 | t.Fatalf("TreeHash = %q, want %q", got, treeID) |
| 36 | } |
| 37 | if len(commit.ParentHashes) != 1 { |
| 38 | t.Fatalf("ParentHashes length = %d, want 1", len(commit.ParentHashes)) |
| 39 | } |
| 40 | if got := commit.ParentHashes[0].String(); got != parentID { |
| 41 | t.Fatalf("ParentHashes[0] = %q, want %q", got, parentID) |
| 42 | } |
| 43 | } |