@@ -7,12 +7,14 @@ import (
7
7
"os"
8
8
"os/exec"
9
9
"testing"
10
+ "time"
10
11
11
12
"github.com/github/git-sizer/counts"
12
13
"github.com/github/git-sizer/git"
13
14
"github.com/github/git-sizer/sizes"
14
15
15
16
"github.com/stretchr/testify/assert"
17
+ "github.com/stretchr/testify/require"
16
18
)
17
19
18
20
// Smoke test that the program runs.
@@ -24,6 +26,24 @@ func TestExec(t *testing.T) {
24
26
}
25
27
}
26
28
29
+ func gitCommand (t * testing.T , repo * git.Repository , args ... string ) * exec.Cmd {
30
+ cmd := exec .Command ("git" , args ... )
31
+ cmd .Env = append (os .Environ (), "GIT_DIR=" + repo .Path ())
32
+ return cmd
33
+ }
34
+
35
+ func addAuthorInfo (cmd * exec.Cmd , timestamp * time.Time ) {
36
+ cmd .Env = append (cmd .Env ,
37
+ "GIT_AUTHOR_NAME=Arthur" ,
38
+
39
+ fmt .Sprintf ("GIT_AUTHOR_DATE=%d -0700" , timestamp .Unix ()),
40
+ "GIT_COMMITTER_NAME=Constance" ,
41
+
42
+ fmt .Sprintf ("GIT_COMMITTER_DATE=%d -0700" , timestamp .Unix ()),
43
+ )
44
+ * timestamp = timestamp .Add (60 * time .Second )
45
+ }
46
+
27
47
func newGitBomb (
28
48
repoName string , depth , breadth int , body string ,
29
49
) (repo * git.Repository , err error ) {
@@ -113,6 +133,7 @@ func pow(x uint64, n int) uint64 {
113
133
}
114
134
115
135
func TestBomb (t * testing.T ) {
136
+ t .Parallel ()
116
137
assert := assert .New (t )
117
138
118
139
repo , err := newGitBomb ("bomb" , 10 , 10 , "boom!\n " )
@@ -157,3 +178,44 @@ func TestBomb(t *testing.T) {
157
178
assert .Equal (counts .Count32 (0 ), h .MaxExpandedLinkCount , "max expanded link count" )
158
179
assert .Equal (counts .Count32 (0 ), h .MaxExpandedSubmoduleCount , "max expanded submodule count" )
159
180
}
181
+
182
+ func TestTaggedTags (t * testing.T ) {
183
+ t .Parallel ()
184
+ path , err := ioutil .TempDir ("" , "tagged-tags" )
185
+ require .NoError (t , err , "creating temporary directory" )
186
+
187
+ defer func () {
188
+ os .RemoveAll (path )
189
+ }()
190
+
191
+ cmd := exec .Command ("git" , "init" , path )
192
+ require .NoError (t , cmd .Run (), "initializing repo" )
193
+ repo , err := git .NewRepository (path )
194
+ require .NoError (t , err , "initializing Repository object" )
195
+
196
+ timestamp := time .Unix (1112911993 , 0 )
197
+
198
+ cmd = gitCommand (t , repo , "commit" , "-m" , "initial" , "--allow-empty" )
199
+ addAuthorInfo (cmd , & timestamp )
200
+ require .NoError (t , cmd .Run (), "creating commit" )
201
+
202
+ // The lexicographical order of these tags is important, hence
203
+ // their strange names.
204
+ cmd = gitCommand (t , repo , "tag" , "-m" , "tag 1" , "tag" , "master" )
205
+ addAuthorInfo (cmd , & timestamp )
206
+ require .NoError (t , cmd .Run (), "creating tag 1" )
207
+
208
+ cmd = gitCommand (t , repo , "tag" , "-m" , "tag 2" , "bag" , "tag" )
209
+ addAuthorInfo (cmd , & timestamp )
210
+ require .NoError (t , cmd .Run (), "creating tag 2" )
211
+
212
+ cmd = gitCommand (t , repo , "tag" , "-m" , "tag 3" , "wag" , "bag" )
213
+ addAuthorInfo (cmd , & timestamp )
214
+ require .NoError (t , cmd .Run (), "creating tag 3" )
215
+
216
+ h , err := sizes .ScanRepositoryUsingGraph (
217
+ repo , git .AllReferencesFilter , sizes .NameStyleNone , false ,
218
+ )
219
+ require .NoError (t , err , "scanning repository" )
220
+ assert .Equal (t , counts .Count32 (3 ), h .MaxTagDepth , "tag depth" )
221
+ }
0 commit comments