mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-20 04:00:40 -04:00
Using url.Parse to parse an absolute file path on Windows yields a URL type where the Path element is prefixed by a slash. For example, parsing "file:///C:/Users/user" gives a URL type with Path:"/C:/Users/user". According to golang.org/issue/6027, the parsing is correct as is. The leading slash on the Path must be eliminated before any file operations. This commit introduces a urlParse function which wraps the url.Parse functionality and removes the leading slash in Path for absolute file paths on Windows. Fixes config/module test failures on Windows.
57 lines
917 B
Go
57 lines
917 B
Go
package module
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
)
|
|
|
|
const fixtureDir = "./test-fixtures"
|
|
|
|
func tempDir(t *testing.T) string {
|
|
dir, err := ioutil.TempDir("", "tf")
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
if err := os.RemoveAll(dir); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
return dir
|
|
}
|
|
|
|
func testConfig(t *testing.T, n string) *config.Config {
|
|
c, err := config.LoadDir(filepath.Join(fixtureDir, n))
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
return c
|
|
}
|
|
|
|
func testModule(n string) string {
|
|
p := filepath.Join(fixtureDir, n)
|
|
p, err := filepath.Abs(p)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return fmtFileURL(p)
|
|
}
|
|
|
|
func testModuleURL(n string) *url.URL {
|
|
u, err := urlParse(testModule(n))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return u
|
|
}
|
|
|
|
func testStorage(t *testing.T) Storage {
|
|
return &FolderStorage{StorageDir: tempDir(t)}
|
|
}
|