@@ -8,11 +8,15 @@ import (
8
8
"context"
9
9
"io/ioutil"
10
10
"net/url"
11
+ "os"
11
12
"os/exec"
13
+ "path/filepath"
12
14
"reflect"
13
15
"strings"
14
16
"sync"
15
17
"testing"
18
+
19
+ "github.com/golang/dep/internal/test"
16
20
)
17
21
18
22
// Parent test that executes all the slow vcs interaction tests in parallel.
@@ -321,7 +325,7 @@ func testBzrSourceInteractions(t *testing.T) {
321
325
322
326
err = isrc .initLocal (ctx )
323
327
if err != nil {
324
- t .Fatalf ("Error on cloning git repo: %s" , err )
328
+ t .Fatalf ("Error on cloning bzr repo: %s" , err )
325
329
}
326
330
327
331
src , ok := isrc .(* bzrSource )
@@ -433,7 +437,7 @@ func testHgSourceInteractions(t *testing.T) {
433
437
434
438
err = isrc .initLocal (ctx )
435
439
if err != nil {
436
- t .Fatalf ("Error on cloning git repo: %s" , err )
440
+ t .Fatalf ("Error on cloning hg repo: %s" , err )
437
441
}
438
442
439
443
src , ok := isrc .(* hgSource )
@@ -520,6 +524,114 @@ func testHgSourceInteractions(t *testing.T) {
520
524
<- donech
521
525
}
522
526
527
+ func Test_bzrSource_exportRevisionTo_removeVcsFiles (t * testing.T ) {
528
+ t .Parallel ()
529
+
530
+ // This test is slow, so skip it on -short
531
+ if testing .Short () {
532
+ t .Skip ("Skipping hg source version fetching test in short mode" )
533
+ }
534
+ requiresBins (t , "bzr" )
535
+
536
+ h := test .NewHelper (t )
537
+ defer h .Cleanup ()
538
+ h .TempDir ("smcache" )
539
+ cpath := h .Path ("smcache" )
540
+ repoPath := filepath .Join (h .Path ("." ), "repo" )
541
+
542
+ rev := Revision (
"[email protected] " )
543
+ n := "launchpad.net/govcstestbzrrepo"
544
+ un := "https://" + n
545
+ u , err := url .Parse (un )
546
+ if err != nil {
547
+ t .Errorf ("URL was bad, lolwut? errtext: %s" , err )
548
+ return
549
+ }
550
+ mb := maybeBzrSource {u }
551
+
552
+ ctx := context .Background ()
553
+ superv := newSupervisor (ctx )
554
+ isrc , _ , err := mb .try (ctx , cpath , newMemoryCache (), superv )
555
+ if err != nil {
556
+ t .Fatalf ("unexpected error while setting up hgSource for test repo: %s" , err )
557
+ }
558
+
559
+ err = isrc .initLocal (ctx )
560
+ if err != nil {
561
+ t .Fatalf ("Error on cloning bzr repo: %s" , err )
562
+ }
563
+
564
+ src , ok := isrc .(* bzrSource )
565
+ if ! ok {
566
+ t .Fatalf ("expected a bzrSource, got a %T" , isrc )
567
+ }
568
+
569
+ if err := src .exportRevisionTo (ctx , rev , repoPath ); err != nil {
570
+ t .Fatalf ("unexpected error: %v" , err )
571
+ }
572
+
573
+ _ , err = os .Stat (filepath .Join (repoPath , ".bzr" ))
574
+ if err == nil {
575
+ t .Fatal ("expected .bzr/ to not exists" )
576
+ } else if ! os .IsNotExist (err ) {
577
+ t .Fatalf ("unexpected error: %v" , err )
578
+ }
579
+ }
580
+
581
+ func Test_hgSource_exportRevisionTo_removeVcsFiles (t * testing.T ) {
582
+ t .Parallel ()
583
+
584
+ // This test is slow, so skip it on -short
585
+ if testing .Short () {
586
+ t .Skip ("Skipping hg source version fetching test in short mode" )
587
+ }
588
+ requiresBins (t , "hg" )
589
+
590
+ h := test .NewHelper (t )
591
+ defer h .Cleanup ()
592
+ h .TempDir ("smcache" )
593
+ cpath := h .Path ("smcache" )
594
+ repoPath := filepath .Join (h .Path ("." ), "repo" )
595
+
596
+ rev := Revision ("6f55e1f03d91f8a7cce35d1968eb60a2352e4d59" )
597
+ n := "bitbucket.org/golang-dep/dep-test"
598
+ un := "https://" + n
599
+ u , err := url .Parse (un )
600
+ if err != nil {
601
+ t .Errorf ("URL was bad, lolwut? errtext: %s" , err )
602
+ return
603
+ }
604
+ mb := maybeHgSource {u }
605
+
606
+ ctx := context .Background ()
607
+ superv := newSupervisor (ctx )
608
+ isrc , _ , err := mb .try (ctx , cpath , newMemoryCache (), superv )
609
+ if err != nil {
610
+ t .Fatalf ("unexpected error while setting up hgSource for test repo: %s" , err )
611
+ }
612
+
613
+ err = isrc .initLocal (ctx )
614
+ if err != nil {
615
+ t .Fatalf ("Error on cloning hg repo: %s" , err )
616
+ }
617
+
618
+ src , ok := isrc .(* hgSource )
619
+ if ! ok {
620
+ t .Fatalf ("expected a hgSource, got a %T" , isrc )
621
+ }
622
+
623
+ if err := src .exportRevisionTo (ctx , rev , repoPath ); err != nil {
624
+ t .Fatalf ("unexpected error: %v" , err )
625
+ }
626
+
627
+ _ , err = os .Stat (filepath .Join (repoPath , ".hg" ))
628
+ if err == nil {
629
+ t .Fatal ("expected .hg/ to not exists" )
630
+ } else if ! os .IsNotExist (err ) {
631
+ t .Fatalf ("unexpected error: %v" , err )
632
+ }
633
+ }
634
+
523
635
// Fail a test if the specified binaries aren't installed.
524
636
func requiresBins (t * testing.T , bins ... string ) {
525
637
for _ , b := range bins {
0 commit comments