@@ -10,6 +10,7 @@ import (
10
10
"cmd/go/internal/webtest"
11
11
"io"
12
12
"io/ioutil"
13
+ "log"
13
14
"os"
14
15
"reflect"
15
16
"strings"
@@ -21,6 +22,21 @@ func init() {
21
22
isTest = true
22
23
}
23
24
25
+ func TestMain (m * testing.M ) {
26
+ os .Exit (testMain (m ))
27
+ }
28
+
29
+ func testMain (m * testing.M ) int {
30
+ dir , err := ioutil .TempDir ("" , "gitrepo-test-" )
31
+ if err != nil {
32
+ log .Fatal (err )
33
+ }
34
+ defer os .RemoveAll (dir )
35
+
36
+ codehost .WorkRoot = dir
37
+ return m .Run ()
38
+ }
39
+
24
40
var codeRepoTests = []struct {
25
41
path string
26
42
lookerr string
@@ -119,12 +135,12 @@ var codeRepoTests = []struct {
119
135
{
120
136
path : "github.com/rsc/vgotest1/submod" ,
121
137
rev : "v1.0.0" ,
122
- err : "404 Not Found" , // TODO
138
+ err : "unknown revision \" submod/v1.0.0 \" " ,
123
139
},
124
140
{
125
141
path : "github.com/rsc/vgotest1/submod" ,
126
142
rev : "v1.0.3" ,
127
- err : "404 Not Found" , // TODO
143
+ err : "unknown revision \" submod/v1.0.3 \" " ,
128
144
},
129
145
{
130
146
path : "github.com/rsc/vgotest1/submod" ,
@@ -228,16 +244,6 @@ var codeRepoTests = []struct {
228
244
time : time .Date (2018 , 2 , 14 , 0 , 45 , 20 , 0 , time .UTC ),
229
245
gomod : "module \" rsc.io/quote\" \n " ,
230
246
},
231
- {
232
- // redirect to bitbucket
233
- path : "example.net/vgotest" ,
234
- rev : "v1.0.0" ,
235
- version : "v1.0.0" ,
236
- name : "9152736a7559a4b73ca45d36fe457cb617c3b207" ,
237
- short : "9152736a7559" ,
238
- time : time .Date (2017 , 8 , 22 , 3 , 10 , 13 , 0 , time .UTC ),
239
- gomod : "module \" example.net/vgotest\" \n " ,
240
- },
241
247
{
242
248
// redirect to static hosting proxy
243
249
path : "swtch.com/testmod" ,
@@ -308,13 +314,13 @@ var codeRepoTests = []struct {
308
314
gomod : "module \" gopkg.in/yaml.v2\" \n \n require (\n \t \" gopkg.in/check.v1\" v0.0.0-20161208181325-20d25e280405\n )\n " ,
309
315
},
310
316
{
311
- path : "github.com/gobuffalo/buffalo " ,
312
- rev : "development " ,
313
- version : "v0.0.0-20180406185414-59b4005674b6 " ,
314
- name : "59b4005674b633728e2bfc3bb09cc204f7c2d6f5 " ,
315
- short : "59b4005674b6 " ,
316
- time : time .Date (2018 , 4 , 6 , 18 , 54 , 14 , 0 , time .UTC ),
317
- gomod : "//vgo 0.0.4\n \n module github.com/gobuffalo/buffalo \n " ,
317
+ path : "vcs-test.golang.org/go/mod/gitrepo1 " ,
318
+ rev : "master " ,
319
+ version : "v0.0.0-20180417194322-ede458df7cd0 " ,
320
+ name : "ede458df7cd0fdca520df19a33158086a8a68e81 " ,
321
+ short : "ede458df7cd0 " ,
322
+ time : time .Date (2018 , 4 , 17 , 19 , 43 , 22 , 0 , time .UTC ),
323
+ gomod : "//vgo 0.0.4\n \n module vcs-test.golang.org/go/mod/gitrepo1 \n " ,
318
324
},
319
325
}
320
326
@@ -528,63 +534,26 @@ func TestCodeRepoVersions(t *testing.T) {
528
534
}
529
535
}
530
536
531
- var latestAtTests = []struct {
537
+ var latestTests = []struct {
532
538
path string
533
- time time.Time
534
- branch string
535
539
version string
536
540
err string
537
541
}{
538
542
{
539
- path : "github.com/rsc/vgotest1" ,
540
- time : time .Date (2018 , 1 , 20 , 0 , 0 , 0 , 0 , time .UTC ),
543
+ path : "github.com/rsc/empty" ,
541
544
err : "no commits" ,
542
545
},
543
546
{
544
547
path : "github.com/rsc/vgotest1" ,
545
- time : time .Date (2018 , 2 , 20 , 0 , 0 , 0 , 0 , time .UTC ),
546
548
version : "v0.0.0-20180219223237-a08abb797a67" ,
547
549
},
548
- {
549
- path : "github.com/rsc/vgotest1" ,
550
- time : time .Date (2018 , 2 , 20 , 0 , 0 , 0 , 0 , time .UTC ),
551
- branch : "mybranch" ,
552
- version : "v0.0.0-20180219231006-80d85c5d4d17" ,
553
- },
554
550
{
555
551
path : "swtch.com/testmod" ,
556
- time : time .Date (2000 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
557
- version : "v1.0.0" ,
558
- },
559
- {
560
- path : "swtch.com/testmod" ,
561
- time : time .Date (3000 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
562
552
version : "v1.1.1" ,
563
553
},
564
- {
565
- path : "swtch.com/testmod" ,
566
- time : time .Date (3000 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
567
- branch : "branch" ,
568
- err : "latest on branch not supported" ,
569
- },
570
- {
571
- path : "gopkg.in/check.v1" ,
572
- time : time .Date (2018 , 2 , 20 , 15 , 53 , 33 , 0 , time .UTC ),
573
- version : "v0.0.0-20161208181325-20d25e280405" ,
574
- },
575
- {
576
- path : "gopkg.in/yaml.v2" ,
577
- time : time .Date (2018 , 2 , 20 , 15 , 53 , 33 , 0 , time .UTC ),
578
- version : "v0.0.0-20180109114331-d670f9405373" ,
579
- },
580
- {
581
- path : "gopkg.in/russross/blackfriday.v2" ,
582
- time : time .Date (2018 , 2 , 20 , 15 , 53 , 33 , 0 , time .UTC ),
583
- version : "v0.0.0-20180212083338-119f356b88f8" ,
584
- },
585
554
}
586
555
587
- func TestLatestAt (t * testing.T ) {
556
+ func TestLatest (t * testing.T ) {
588
557
webtest .LoadOnce ("testdata/webtest.txt" )
589
558
webtest .Hook ()
590
559
defer webtest .Unhook ()
@@ -594,28 +563,25 @@ func TestLatestAt(t *testing.T) {
594
563
t .Fatal (err )
595
564
}
596
565
defer os .RemoveAll (tmpdir )
597
- for _ , tt := range latestAtTests {
598
- name := strings .Replace (tt .path , "/" , "_" , - 1 ) + "/" + tt .time .Format ("2006-01-02_15:04:05" )
599
- if tt .branch != "" {
600
- name += "/" + tt .branch
601
- }
566
+ for _ , tt := range latestTests {
567
+ name := strings .Replace (tt .path , "/" , "_" , - 1 )
602
568
t .Run (name , func (t * testing.T ) {
603
569
repo , err := Lookup (tt .path )
604
570
if err != nil {
605
571
t .Fatalf ("Lookup(%q): %v" , tt .path , err )
606
572
}
607
- info , err := repo .LatestAt ( tt . time , tt . branch )
573
+ info , err := repo .Latest ( )
608
574
if err != nil {
609
575
if tt .err != "" {
610
576
if err .Error () == tt .err {
611
577
return
612
578
}
613
- t .Fatalf ("LatestAt(%v, %q ): %v, want %q" , tt . time , tt . branch , err , tt .err )
579
+ t .Fatalf ("Latest( ): %v, want %q" , err , tt .err )
614
580
}
615
- t .Fatalf ("LatestAt(%v, %q ): %v" , tt . time , tt . branch , err )
581
+ t .Fatalf ("Latest( ): %v" , err )
616
582
}
617
583
if info .Version != tt .version {
618
- t .Fatalf ("LatestAt(%v, %q ) = %v, want %v" , tt . time , tt . branch , info .Version , tt .version )
584
+ t .Fatalf ("Latest( ) = %v, want %v" , info .Version , tt .version )
619
585
}
620
586
})
621
587
}
0 commit comments