Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 216ca2e

Browse files
committed
internal/gps: add tests to bzrSource.exportRevisionTo and hgSource.exportRevisionTo
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent a8650d3 commit 216ca2e

File tree

2 files changed

+115
-5
lines changed

2 files changed

+115
-5
lines changed

internal/gps/vcs_source.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ type bzrSource struct {
351351
}
352352

353353
func (s *bzrSource) exportRevisionTo(ctx context.Context, rev Revision, to string) error {
354-
// TODO: use bzr instead of the generic approach in
355-
// baseVCSSource.exportRevisionTo to make it faster.
356354
if err := s.baseVCSSource.exportRevisionTo(ctx, rev, to); err != nil {
357355
return err
358356
}
@@ -415,7 +413,7 @@ type hgSource struct {
415413
}
416414

417415
func (s *hgSource) exportRevisionTo(ctx context.Context, rev Revision, to string) error {
418-
// TODO: use bzr instead of the generic approach in
416+
// TODO: use hg instead of the generic approach in
419417
// baseVCSSource.exportRevisionTo to make it faster.
420418
if err := s.baseVCSSource.exportRevisionTo(ctx, rev, to); err != nil {
421419
return err

internal/gps/vcs_source_test.go

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import (
88
"context"
99
"io/ioutil"
1010
"net/url"
11+
"os"
1112
"os/exec"
13+
"path/filepath"
1214
"reflect"
1315
"strings"
1416
"sync"
1517
"testing"
18+
19+
"github.com/golang/dep/internal/test"
1620
)
1721

1822
// Parent test that executes all the slow vcs interaction tests in parallel.
@@ -321,7 +325,7 @@ func testBzrSourceInteractions(t *testing.T) {
321325

322326
err = isrc.initLocal(ctx)
323327
if err != nil {
324-
t.Fatalf("Error on cloning git repo: %s", err)
328+
t.Fatalf("Error on cloning bzr repo: %s", err)
325329
}
326330

327331
src, ok := isrc.(*bzrSource)
@@ -433,7 +437,7 @@ func testHgSourceInteractions(t *testing.T) {
433437

434438
err = isrc.initLocal(ctx)
435439
if err != nil {
436-
t.Fatalf("Error on cloning git repo: %s", err)
440+
t.Fatalf("Error on cloning hg repo: %s", err)
437441
}
438442

439443
src, ok := isrc.(*hgSource)
@@ -520,6 +524,114 @@ func testHgSourceInteractions(t *testing.T) {
520524
<-donech
521525
}
522526

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+
523635
// Fail a test if the specified binaries aren't installed.
524636
func requiresBins(t *testing.T, bins ...string) {
525637
for _, b := range bins {

0 commit comments

Comments
 (0)