Added file with correct line endings

When dealing with windows the file url format is file:///c:/
On windows a lot of git clients will convert LF to CRLF. This would be a problem where file contents are compared exactly
This commit is contained in:
Taliesin Sisson 2016-04-01 10:55:02 +01:00
parent 807d7eaced
commit e5510873bb
4 changed files with 25 additions and 5 deletions

View File

@ -120,7 +120,7 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
}()
// Test some cases with and without a schema prefix
for _, prefix := range []string{"", "file://"} {
for _, prefix := range []string{"", filePrefix} {
// Nonexistent file
_, err = DownloadableURL(prefix + "i/dont/exist")
if err != nil {

View File

@ -8,6 +8,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"runtime"
"testing"
)
@ -56,6 +57,7 @@ func TestDownloadClient_basic(t *testing.T) {
Url: ts.URL + "/basic.txt",
TargetPath: tf.Name(),
})
path, err := client.Get()
if err != nil {
t.Fatalf("err: %s", err)
@ -352,7 +354,13 @@ func TestDownloadFileUrl(t *testing.T) {
// source_path is a file path and source is a network path
sourcePath := fmt.Sprintf("%s/test-fixtures/fileurl/%s", cwd, "cake")
source := fmt.Sprintf("file://" + sourcePath)
filePrefix := "file://"
if runtime.GOOS == "windows" {
filePrefix += "/"
}
source := fmt.Sprintf(filePrefix + sourcePath)
t.Logf("Trying to download %s", source)
config := &DownloadConfig{

View File

@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/mitchellh/packer/template/interpolate"
@ -77,7 +78,13 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
return warnings, errs
}
case "file":
file, err := os.Open(u.Path)
path := u.Path
if runtime.GOOS == "windows" && len(path) > 2 && path[0] == '/' && path[2] == ':' {
path = strings.TrimLeft(path, "/")
}
file, err := os.Open(path)
if err != nil {
errs = append(errs, err)
return warnings, errs

View File

@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"runtime"
"testing"
)
@ -80,7 +81,11 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i.ISOChecksum = ""
cs_file, _ := ioutil.TempFile("", "packer-test-")
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style), 0666)
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
filePrefix := "file://"
if runtime.GOOS == "windows" {
filePrefix += "/"
}
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
warns, err = i.Prepare(nil)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
@ -98,7 +103,7 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
i.ISOChecksum = ""
cs_file, _ = ioutil.TempFile("", "packer-test-")
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
warns, err = i.Prepare(nil)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)