-
Notifications
You must be signed in to change notification settings - Fork 242
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 #162 from hashicorp/fix_url_parse_windows
Fix tests for windows
- Loading branch information
Showing
10 changed files
with
81 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ addons: | |
|
||
language: go | ||
|
||
os: | ||
- linux | ||
- osx | ||
|
||
go: | ||
- "1.11.x" | ||
|
||
|
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ install: | |
go get -d -v -t ./... | ||
build_script: | ||
- cmd: go test -v ./... | ||
- cmd: go test ./... |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package getter | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"io/ioutil" | ||
"net/url" | ||
|
@@ -10,6 +11,8 @@ import ( | |
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
urlhelper "github.com/hashicorp/go-getter/helper/url" | ||
) | ||
|
||
var testHasGit bool | ||
|
@@ -26,8 +29,7 @@ func TestGitGetter_impl(t *testing.T) { | |
|
||
func TestGitGetter(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
|
@@ -50,8 +52,7 @@ func TestGitGetter(t *testing.T) { | |
|
||
func TestGitGetter_branch(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
|
@@ -89,8 +90,7 @@ func TestGitGetter_branch(t *testing.T) { | |
|
||
func TestGitGetter_branchUpdate(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
|
@@ -132,8 +132,7 @@ func TestGitGetter_branchUpdate(t *testing.T) { | |
|
||
func TestGitGetter_tag(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
|
@@ -171,8 +170,7 @@ func TestGitGetter_tag(t *testing.T) { | |
|
||
func TestGitGetter_GetFile(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
|
@@ -196,6 +194,12 @@ func TestGitGetter_GetFile(t *testing.T) { | |
} | ||
|
||
func TestGitGetter_gitVersion(t *testing.T) { | ||
if !testHasGit { | ||
t.Skip("git not found, skipping") | ||
} | ||
if runtime.GOOS == "windows" { | ||
t.Skip("skipping on windows since the test requires sh") | ||
} | ||
dir, err := ioutil.TempDir("", "go-getter") | ||
if err != nil { | ||
t.Fatal(err) | ||
|
@@ -230,16 +234,19 @@ func TestGitGetter_gitVersion(t *testing.T) { | |
|
||
func TestGitGetter_sshKey(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
dst := tempDir(t) | ||
|
||
encodedKey := base64.StdEncoding.EncodeToString([]byte(testGitToken)) | ||
|
||
u, err := url.Parse("ssh://[email protected]/hashicorp/test-private-repo" + | ||
// avoid getting locked by a github authenticity validation prompt | ||
os.Setenv("GIT_SSH_COMMAND", "ssh -o StrictHostKeyChecking=no") | ||
defer os.Setenv("GIT_SSH_COMMAND", "") | ||
|
||
u, err := urlhelper.Parse("ssh://[email protected]/hashicorp/test-private-repo" + | ||
"?sshkey=" + encodedKey) | ||
if err != nil { | ||
t.Fatal(err) | ||
|
@@ -257,27 +264,36 @@ func TestGitGetter_sshKey(t *testing.T) { | |
|
||
func TestGitGetter_submodule(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
t.Skip("git not found, skipping") | ||
} | ||
|
||
g := new(GitGetter) | ||
dst := tempDir(t) | ||
|
||
relpath := func(basepath, targpath string) string { | ||
relpath, err := filepath.Rel(basepath, targpath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return strings.Replace(relpath, `\`, `/`, -1) | ||
// on windows git still prefers relatives paths | ||
// containing `/` for submodules | ||
} | ||
|
||
// Set up the grandchild | ||
gc := testGitRepo(t, "grandchild") | ||
gc.commitFile("grandchild.txt", "grandchild") | ||
|
||
// Set up the child | ||
c := testGitRepo(t, "child") | ||
c.commitFile("child.txt", "child") | ||
c.git("submodule", "add", gc.dir) | ||
c.git("submodule", "add", "-f", relpath(c.dir, gc.dir)) | ||
c.git("commit", "-m", "Add grandchild submodule") | ||
|
||
// Set up the parent | ||
p := testGitRepo(t, "parent") | ||
p.commitFile("parent.txt", "parent") | ||
p.git("submodule", "add", c.dir) | ||
p.git("submodule", "add", "-f", relpath(p.dir, c.dir)) | ||
p.git("commit", "-m", "Add child submodule") | ||
|
||
// Clone the root repository | ||
|
@@ -299,8 +315,7 @@ func TestGitGetter_submodule(t *testing.T) { | |
|
||
func TestGitGetter_setupGitEnv_sshKey(t *testing.T) { | ||
if runtime.GOOS == "windows" { | ||
t.Skipf("skipping on windows since the test requires sh") | ||
return | ||
t.Skip("skipping on windows since the test requires sh") | ||
} | ||
|
||
cmd := exec.Command("/bin/sh", "-c", "echo $GIT_SSH_COMMAND") | ||
|
@@ -362,12 +377,13 @@ func testGitRepo(t *testing.T, name string) *gitRepo { | |
dir: dir, | ||
} | ||
|
||
url, err := url.Parse("file://" + r.dir) | ||
url, err := urlhelper.Parse("file://" + r.dir) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
r.url = url | ||
|
||
t.Logf("initializing git repo in %s", dir) | ||
r.git("init") | ||
r.git("config", "user.name", "go-getter") | ||
r.git("config", "user.email", "[email protected]") | ||
|
@@ -379,8 +395,10 @@ func testGitRepo(t *testing.T, name string) *gitRepo { | |
func (r *gitRepo) git(args ...string) { | ||
cmd := exec.Command("git", args...) | ||
cmd.Dir = r.dir | ||
bfr := bytes.NewBuffer(nil) | ||
cmd.Stderr = bfr | ||
if err := cmd.Run(); err != nil { | ||
r.t.Fatal(err) | ||
r.t.Fatal(err, bfr.String()) | ||
} | ||
} | ||
|
||
|
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
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