This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #888 from ibrasho-forks/remove-vcs-directories-fro…
…m-vendor internal/gps: remove vcs (bzr & hg) directories when coping to vendor/
- Loading branch information
Showing
2 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,15 @@ import ( | |
"context" | ||
"io/ioutil" | ||
"net/url" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"reflect" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/golang/dep/internal/test" | ||
) | ||
|
||
// Parent test that executes all the slow vcs interaction tests in parallel. | ||
|
@@ -321,7 +325,7 @@ func testBzrSourceInteractions(t *testing.T) { | |
|
||
err = isrc.initLocal(ctx) | ||
if err != nil { | ||
t.Fatalf("Error on cloning git repo: %s", err) | ||
t.Fatalf("Error on cloning bzr repo: %s", err) | ||
} | ||
|
||
src, ok := isrc.(*bzrSource) | ||
|
@@ -433,7 +437,7 @@ func testHgSourceInteractions(t *testing.T) { | |
|
||
err = isrc.initLocal(ctx) | ||
if err != nil { | ||
t.Fatalf("Error on cloning git repo: %s", err) | ||
t.Fatalf("Error on cloning hg repo: %s", err) | ||
} | ||
|
||
src, ok := isrc.(*hgSource) | ||
|
@@ -520,6 +524,114 @@ func testHgSourceInteractions(t *testing.T) { | |
<-donech | ||
} | ||
|
||
func Test_bzrSource_exportRevisionTo_removeVcsFiles(t *testing.T) { | ||
t.Parallel() | ||
|
||
// This test is slow, so skip it on -short | ||
if testing.Short() { | ||
t.Skip("Skipping hg source version fetching test in short mode") | ||
} | ||
requiresBins(t, "bzr") | ||
|
||
h := test.NewHelper(t) | ||
defer h.Cleanup() | ||
h.TempDir("smcache") | ||
cpath := h.Path("smcache") | ||
repoPath := filepath.Join(h.Path("."), "repo") | ||
|
||
rev := Revision("[email protected]") | ||
n := "launchpad.net/govcstestbzrrepo" | ||
un := "https://" + n | ||
u, err := url.Parse(un) | ||
if err != nil { | ||
t.Errorf("URL was bad, lolwut? errtext: %s", err) | ||
return | ||
} | ||
mb := maybeBzrSource{u} | ||
|
||
ctx := context.Background() | ||
superv := newSupervisor(ctx) | ||
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv) | ||
if err != nil { | ||
t.Fatalf("unexpected error while setting up hgSource for test repo: %s", err) | ||
} | ||
|
||
err = isrc.initLocal(ctx) | ||
if err != nil { | ||
t.Fatalf("Error on cloning bzr repo: %s", err) | ||
} | ||
|
||
src, ok := isrc.(*bzrSource) | ||
if !ok { | ||
t.Fatalf("expected a bzrSource, got a %T", isrc) | ||
} | ||
|
||
if err := src.exportRevisionTo(ctx, rev, repoPath); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
_, err = os.Stat(filepath.Join(repoPath, ".bzr")) | ||
if err == nil { | ||
t.Fatal("expected .bzr/ to not exists") | ||
} else if !os.IsNotExist(err) { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
} | ||
|
||
func Test_hgSource_exportRevisionTo_removeVcsFiles(t *testing.T) { | ||
t.Parallel() | ||
|
||
// This test is slow, so skip it on -short | ||
if testing.Short() { | ||
t.Skip("Skipping hg source version fetching test in short mode") | ||
} | ||
requiresBins(t, "hg") | ||
|
||
h := test.NewHelper(t) | ||
defer h.Cleanup() | ||
h.TempDir("smcache") | ||
cpath := h.Path("smcache") | ||
repoPath := filepath.Join(h.Path("."), "repo") | ||
|
||
rev := Revision("6f55e1f03d91f8a7cce35d1968eb60a2352e4d59") | ||
n := "bitbucket.org/golang-dep/dep-test" | ||
un := "https://" + n | ||
u, err := url.Parse(un) | ||
if err != nil { | ||
t.Errorf("URL was bad, lolwut? errtext: %s", err) | ||
return | ||
} | ||
mb := maybeHgSource{u} | ||
|
||
ctx := context.Background() | ||
superv := newSupervisor(ctx) | ||
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv) | ||
if err != nil { | ||
t.Fatalf("unexpected error while setting up hgSource for test repo: %s", err) | ||
} | ||
|
||
err = isrc.initLocal(ctx) | ||
if err != nil { | ||
t.Fatalf("Error on cloning hg repo: %s", err) | ||
} | ||
|
||
src, ok := isrc.(*hgSource) | ||
if !ok { | ||
t.Fatalf("expected a hgSource, got a %T", isrc) | ||
} | ||
|
||
if err := src.exportRevisionTo(ctx, rev, repoPath); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
_, err = os.Stat(filepath.Join(repoPath, ".hg")) | ||
if err == nil { | ||
t.Fatal("expected .hg/ to not exists") | ||
} else if !os.IsNotExist(err) { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
} | ||
|
||
// Fail a test if the specified binaries aren't installed. | ||
func requiresBins(t *testing.T, bins ...string) { | ||
for _, b := range bins { | ||
|