From 92e68c1ee6217e33d1b48a3a04308085de4346bf Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Wed, 28 Jan 2015 06:22:35 +0100 Subject: [PATCH 1/4] command: fix test failure on Windows Adjust the laddr argument to net.Listen to the form host:port, as documented for net.Dial. Fixes a test failure on Windows. --- command/apply_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/apply_test.go b/command/apply_test.go index 6c8643b871..c062de5afd 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -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) } From b40c2fe997cabb80d59d3a167f0de2b8c6c4592f Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Wed, 28 Jan 2015 06:39:16 +0100 Subject: [PATCH 2/4] command: fix test failure on Windows URLs are `/`-based. Windows path Separator is `\`. Convert `\` in test fixture path to `/` with filepath.ToSlash such that proper URLs are constructed even on Windows. Fixes a test failure on Windows. --- command/apply_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/apply_test.go b/command/apply_test.go index c062de5afd..0506b49d67 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -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) From 65177edd1e0f251b026c21855c92e6f9fe9c1d50 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Wed, 28 Jan 2015 07:21:05 +0100 Subject: [PATCH 3/4] config/module: fix test failures on Windows When parsing URLs on Windows, assume it is a drive letter path if the second element is a ':' character. Format the drive letter path as a "file:///"-path prior to parsing the URL. Fixes test failures of the following form in command on Windows: === RUN TestApply_plan --- FAIL: TestApply_plan (0.00s) apply_test.go:379: bad: 1 module download not supported for scheme 'c' --- config/module/url_helper.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config/module/url_helper.go b/config/module/url_helper.go index 061496270a..58c4a8967e 100644 --- a/config/module/url_helper.go +++ b/config/module/url_helper.go @@ -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 { From 97227a5c70630920af1d1d352dace5f3c90b26c5 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Wed, 28 Jan 2015 10:40:19 +0100 Subject: [PATCH 4/4] config/module: fix detection of file paths on Windows Absolute file paths were not correctly detected by module.Detect when using url.Parse to parse the source URL. Wrap the detection with urlParse to properly handle file path detections on Windows. Fixes command test failures on Windows. --- config/module/detect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/module/detect.go b/config/module/detect.go index bdf54f9f80..f70e69a478 100644 --- a/config/module/detect.go +++ b/config/module/detect.go @@ -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 {