-
Notifications
You must be signed in to change notification settings - Fork 31
/
vcs_git_test.go
82 lines (79 loc) · 3.28 KB
/
vcs_git_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
"time"
)
func TestGitCleanOptions(t *testing.T) {
Convey("CleanGitArgs should clean git args correctly", t, func() {
Convey("clean up --pretty args", func() {
args := []string{"--pretty=oneline"}
cleaned := cleanGitArgs(args...)
So(len(cleaned), ShouldEqual, 0)
})
Convey("clean up --date args", func() {
args := []string{"--date=iso"}
cleaned := cleanGitArgs(args...)
So(len(cleaned), ShouldEqual, 0)
})
Convey("do not clean up harmless flags", func() {
args := []string{"--date=iso", "--author=Ivan"}
cleaned := cleanGitArgs(args...)
So(len(cleaned), ShouldEqual, 1)
So(cleaned[0], ShouldEqual, "--author=Ivan")
})
})
}
func TestGitParseCommits(t *testing.T) {
Convey("Parsing commits should work correctly", t, func() {
Convey("Normal case", func() {
lines := []string{
`378739736dd1baa076675c02fe45822bf8936a14|Sun, 18 Oct 2015 22:49:00 +0000|Ivan Daniluk <[email protected]>|Return again`,
`4c6378260658f763d67dea3a931a25daf2a82d51|Sun, 18 Oct 2015 22:48:14 +0000|Ivan Daniluk <[email protected]>|Returned panic`,
`69814659db92a97e077196207815ca12cba7e0dd|Sun, 18 Oct 2015 22:47:54 +0000|Ivan Daniluk <[email protected]>|Added no build`,
`24ebd4283248f85746c69d1d97c7dddedd18d863|Sun, 18 Oct 2015 22:30:15 +0000|Ivan Daniluk <[email protected]>|Remove panic`,
`aec0795b436742b5669fdebd28df702704b8afb2|Sun, 18 Oct 2015 22:29:59 +0000|Ivan Daniluk <[email protected]>|Add panic`,
}
commits := parseGitCommits(lines, time.UTC)
So(len(commits), ShouldEqual, len(lines))
So(commits[0], ShouldResemble, Commit{
Hash: "378739736dd1baa076675c02fe45822bf8936a14",
Author: "Ivan Daniluk <[email protected]>",
Subject: "Return again",
Date: time.Date(2015, time.October, 18, 22, 49, 00, 00, time.UTC),
})
So(commits[4], ShouldResemble, Commit{
Hash: "aec0795b436742b5669fdebd28df702704b8afb2",
Author: "Ivan Daniluk <[email protected]>",
Subject: "Add panic",
Date: time.Date(2015, time.October, 18, 22, 29, 59, 00, time.UTC),
})
})
Convey("Day < 10 case", func() {
lines := []string{
`378739736dd1baa076675c02fe45822bf8936a14|Sun, 8 Oct 2015 22:49:00 +0000|Ivan Daniluk <[email protected]>|Return again`,
}
commits := parseGitCommits(lines, time.UTC)
So(len(commits), ShouldEqual, len(lines))
So(commits[0], ShouldResemble, Commit{
Hash: "378739736dd1baa076675c02fe45822bf8936a14",
Author: "Ivan Daniluk <[email protected]>",
Subject: "Return again",
Date: time.Date(2015, time.October, 8, 22, 49, 00, 00, time.UTC),
})
})
Convey("Separators in subject case", func() {
lines := []string{
`378739736dd1baa076675c02fe45822bf8936a14|Sun, 8 Oct 2015 22:49:00 +0000|Ivan Daniluk <[email protected]>|Return with character'|' and again |[]|`,
}
commits := parseGitCommits(lines, time.UTC)
So(len(commits), ShouldEqual, len(lines))
So(commits[0], ShouldResemble, Commit{
Hash: "378739736dd1baa076675c02fe45822bf8936a14",
Author: "Ivan Daniluk <[email protected]>",
Subject: "Return with character'|' and again |[]|",
Date: time.Date(2015, time.October, 8, 22, 49, 00, 00, time.UTC),
})
})
})
}