@@ -7,12 +7,14 @@ import (
77 "os"
88 "os/exec"
99 "testing"
10+ "time"
1011
1112 "github.com/github/git-sizer/counts"
1213 "github.com/github/git-sizer/git"
1314 "github.com/github/git-sizer/sizes"
1415
1516 "github.com/stretchr/testify/assert"
17+ "github.com/stretchr/testify/require"
1618)
1719
1820// Smoke test that the program runs.
@@ -24,6 +26,24 @@ func TestExec(t *testing.T) {
2426 }
2527}
2628
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+ "GIT_AUTHOR_EMAIL=arthur@example.com" ,
39+ fmt .Sprintf ("GIT_AUTHOR_DATE=%d -0700" , timestamp .Unix ()),
40+ "GIT_COMMITTER_NAME=Constance" ,
41+ "GIT_COMMITTER_EMAIL=constance@example.com" ,
42+ fmt .Sprintf ("GIT_COMMITTER_DATE=%d -0700" , timestamp .Unix ()),
43+ )
44+ * timestamp = timestamp .Add (60 * time .Second )
45+ }
46+
2747func newGitBomb (
2848 repoName string , depth , breadth int , body string ,
2949) (repo * git.Repository , err error ) {
@@ -113,6 +133,7 @@ func pow(x uint64, n int) uint64 {
113133}
114134
115135func TestBomb (t * testing.T ) {
136+ t .Parallel ()
116137 assert := assert .New (t )
117138
118139 repo , err := newGitBomb ("bomb" , 10 , 10 , "boom!\n " )
@@ -157,3 +178,44 @@ func TestBomb(t *testing.T) {
157178 assert .Equal (counts .Count32 (0 ), h .MaxExpandedLinkCount , "max expanded link count" )
158179 assert .Equal (counts .Count32 (0 ), h .MaxExpandedSubmoduleCount , "max expanded submodule count" )
159180}
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