-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
47 lines (39 loc) · 883 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bytes"
"strings"
"testing"
"github.com/go-git/go-git/v5"
)
func TestGetCommits(t *testing.T) {
// use current git repository for testing
repo, err := git.PlainOpen(".")
if err != nil {
t.Fatal(err)
}
ref, err := repo.Head()
if err != nil {
t.Fatal(err)
}
commit, err := repo.CommitObject(ref.Hash())
if err != nil {
t.Fatal(err)
}
var buf bytes.Buffer
err = getCommits(repo, commit, &buf)
if err != nil {
t.Fatal(err)
}
// parse the output with parseLHjson
commits, err := parseLHjson(strings.NewReader(buf.String()))
if err != nil {
t.Fatal(err)
}
// check commits first commit contains the initial commit of bbed8b3 with net 167
if commits[0].ShortHash != "bbed8b3" {
t.Errorf("Expected bbed8b3, got %s", commits[0].ShortHash)
}
if commits[0].Net != 167 {
t.Errorf("Expected 167, got %d", commits[0].Net)
}
}