diff options
| author | Ankur Mittal <[email protected]> | 2017-04-19 18:36:00 -0700 |
|---|---|---|
| committer | Ankur Mittal <[email protected]> | 2017-04-19 18:42:13 -0700 |
| commit | 7caac1fa7b52eb30df29aa3b460f6511993fafd0 (patch) | |
| tree | f9fef9a44fbd7429eccc940d02abf6df8a5d42d8 /object_test.go | |
| parent | 7cd5a4e731e982391b9274e17c7f32050d8e5b15 (diff) | |
Add support for getting short object Id
Diffstat (limited to 'object_test.go')
| -rw-r--r-- | object_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/object_test.go b/object_test.go index cb262de..1b188a8 100644 --- a/object_test.go +++ b/object_test.go @@ -1,6 +1,7 @@ package git import ( + "strings" "testing" ) @@ -105,6 +106,32 @@ func TestObjectOwner(t *testing.T) { checkOwner(t, repo, tree.Object) } +func checkShortId(t *testing.T, Id, shortId string) { + if len(shortId) < 7 || len(shortId) >= len(Id) { + t.Fatal("bad shortId lenght %s", len(shortId)) + } + + if !strings.HasPrefix(Id, shortId) { + t.Fatalf("bad shortId, should be prefix of %s, but is %s\n", Id, shortId) + } +} + +func TestObjectShortId(t *testing.T) { + t.Parallel() + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + commitId, _ := seedTestRepo(t, repo) + + commit, err := repo.LookupCommit(commitId) + checkFatal(t, err) + + shortId, err := commit.ShortId() + checkFatal(t, err) + + checkShortId(t, commitId.String(), shortId) +} + func TestObjectPeel(t *testing.T) { t.Parallel() repo := createTestRepo(t) |
