mirror of
https://github.com/golang/go
synced 2024-11-26 18:16:48 -07:00
cmd/go/internal/modfetch/codehost: skip hg tests if no hg binary is present
Change-Id: I5cf57bf1153eb662bcab71e3d2c04848212559a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/330989 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
00c00558e1
commit
186a3bb4b0
@ -8,7 +8,6 @@ import (
|
|||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
@ -47,12 +46,6 @@ var altRepos = []string{
|
|||||||
var localGitRepo string
|
var localGitRepo string
|
||||||
|
|
||||||
func testMain(m *testing.M) int {
|
func testMain(m *testing.M) int {
|
||||||
if _, err := exec.LookPath("git"); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "skipping because git binary not found")
|
|
||||||
fmt.Println("PASS")
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
dir, err := os.MkdirTemp("", "gitrepo-test-")
|
dir, err := os.MkdirTemp("", "gitrepo-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -60,23 +53,25 @@ func testMain(m *testing.M) int {
|
|||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
if testenv.HasExternalNetwork() && testenv.HasExec() {
|
if testenv.HasExternalNetwork() && testenv.HasExec() {
|
||||||
// Clone gitrepo1 into a local directory.
|
if _, err := exec.LookPath("git"); err == nil {
|
||||||
// If we use a file:// URL to access the local directory,
|
// Clone gitrepo1 into a local directory.
|
||||||
// then git starts up all the usual protocol machinery,
|
// If we use a file:// URL to access the local directory,
|
||||||
// which will let us test remote git archive invocations.
|
// then git starts up all the usual protocol machinery,
|
||||||
localGitRepo = filepath.Join(dir, "gitrepo2")
|
// which will let us test remote git archive invocations.
|
||||||
if _, err := Run("", "git", "clone", "--mirror", gitrepo1, localGitRepo); err != nil {
|
localGitRepo = filepath.Join(dir, "gitrepo2")
|
||||||
log.Fatal(err)
|
if _, err := Run("", "git", "clone", "--mirror", gitrepo1, localGitRepo); err != nil {
|
||||||
}
|
log.Fatal(err)
|
||||||
if _, err := Run(localGitRepo, "git", "config", "daemon.uploadarch", "true"); err != nil {
|
}
|
||||||
log.Fatal(err)
|
if _, err := Run(localGitRepo, "git", "config", "daemon.uploadarch", "true"); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.Run()
|
return m.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRepo(remote string) (Repo, error) {
|
func testRepo(t *testing.T, remote string) (Repo, error) {
|
||||||
if remote == "localGitRepo" {
|
if remote == "localGitRepo" {
|
||||||
// Convert absolute path to file URL. LocalGitRepo will not accept
|
// Convert absolute path to file URL. LocalGitRepo will not accept
|
||||||
// Windows absolute paths because they look like a host:path remote.
|
// Windows absolute paths because they look like a host:path remote.
|
||||||
@ -87,15 +82,17 @@ func testRepo(remote string) (Repo, error) {
|
|||||||
} else {
|
} else {
|
||||||
url = "file:///" + filepath.ToSlash(localGitRepo)
|
url = "file:///" + filepath.ToSlash(localGitRepo)
|
||||||
}
|
}
|
||||||
|
testenv.MustHaveExecPath(t, "git")
|
||||||
return LocalGitRepo(url)
|
return LocalGitRepo(url)
|
||||||
}
|
}
|
||||||
kind := "git"
|
vcs := "git"
|
||||||
for _, k := range []string{"hg"} {
|
for _, k := range []string{"hg"} {
|
||||||
if strings.Contains(remote, "/"+k+"/") {
|
if strings.Contains(remote, "/"+k+"/") {
|
||||||
kind = k
|
vcs = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NewRepo(kind, remote)
|
testenv.MustHaveExecPath(t, vcs)
|
||||||
|
return NewRepo(vcs, remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tagsTests = []struct {
|
var tagsTests = []struct {
|
||||||
@ -116,7 +113,7 @@ func TestTags(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tagsTests {
|
for _, tt := range tagsTests {
|
||||||
f := func(t *testing.T) {
|
f := func(t *testing.T) {
|
||||||
r, err := testRepo(tt.repo)
|
r, err := testRepo(t, tt.repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -168,7 +165,7 @@ func TestLatest(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range latestTests {
|
for _, tt := range latestTests {
|
||||||
f := func(t *testing.T) {
|
f := func(t *testing.T) {
|
||||||
r, err := testRepo(tt.repo)
|
r, err := testRepo(t, tt.repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -221,7 +218,7 @@ func TestReadFile(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range readFileTests {
|
for _, tt := range readFileTests {
|
||||||
f := func(t *testing.T) {
|
f := func(t *testing.T) {
|
||||||
r, err := testRepo(tt.repo)
|
r, err := testRepo(t, tt.repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -412,7 +409,7 @@ func TestReadZip(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range readZipTests {
|
for _, tt := range readZipTests {
|
||||||
f := func(t *testing.T) {
|
f := func(t *testing.T) {
|
||||||
r, err := testRepo(tt.repo)
|
r, err := testRepo(t, tt.repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -581,7 +578,7 @@ func TestStat(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range statTests {
|
for _, tt := range statTests {
|
||||||
f := func(t *testing.T) {
|
f := func(t *testing.T) {
|
||||||
r, err := testRepo(tt.repo)
|
r, err := testRepo(t, tt.repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user