Merge pull request #876 from ceh/command-win-tests

command: fix test failures on OpenBSD, Windows
This commit is contained in:
Mitchell Hashimoto 2015-01-28 08:24:17 -08:00
commit f742ccb606
3 changed files with 11 additions and 6 deletions

View File

@ -1124,7 +1124,7 @@ func TestApply_disableBackup(t *testing.T) {
}
func testHttpServer(t *testing.T) net.Listener {
ln, err := net.Listen("tcp", ":0")
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("err: %s", err)
}
@ -1142,7 +1142,7 @@ func testHttpServer(t *testing.T) net.Listener {
func testHttpHandlerHeader(w http.ResponseWriter, r *http.Request) {
var url url.URL
url.Scheme = "file"
url.Path = testFixturePath("init")
url.Path = filepath.ToSlash(testFixturePath("init"))
w.Header().Add("X-Terraform-Get", url.String())
w.WriteHeader(200)

View File

@ -38,10 +38,10 @@ func Detect(src string, pwd string) (string, error) {
// Separate out the subdir if there is one, we don't pass that to detect
getSrc, subDir := getDirSubdir(getSrc)
u, err := url.Parse(getSrc)
u, err := urlParse(getSrc)
if err == nil && u.Scheme != "" {
// Valid URL
return src, nil
return u.String(), nil
}
for _, d := range Detectors {

View File

@ -9,8 +9,13 @@ import (
func urlParse(rawURL string) (*url.URL, error) {
if runtime.GOOS == "windows" {
// Make sure we're using "/" on Windows. URLs are "/"-based.
rawURL = filepath.ToSlash(rawURL)
if len(rawURL) > 1 && rawURL[1] == ':' {
// Assume we're dealing with a file path.
rawURL = fmtFileURL(rawURL)
} else {
// Make sure we're using "/" on Windows. URLs are "/"-based.
rawURL = filepath.ToSlash(rawURL)
}
}
u, err := url.Parse(rawURL)
if err != nil {