Fix filepath handling on Windows (#1754)
This commit is contained in:
parent
08db073958
commit
ded0f1049a
|
|
@ -1522,7 +1522,7 @@ func TestLoadDesiredStateFromYaml_DuplicateReleaseName(t *testing.T) {
|
||||||
stage: post
|
stage: post
|
||||||
`)
|
`)
|
||||||
readFile := func(filename string) ([]byte, error) {
|
readFile := func(filename string) ([]byte, error) {
|
||||||
if filename != yamlFile {
|
if filepath.ToSlash(filename) != yamlFile {
|
||||||
return nil, fmt.Errorf("unexpected filename: %s", filename)
|
return nil, fmt.Errorf("unexpected filename: %s", filename)
|
||||||
}
|
}
|
||||||
return yamlContent, nil
|
return yamlContent, nil
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type TestFs struct {
|
||||||
func NewTestFs(files map[string]string) *TestFs {
|
func NewTestFs(files map[string]string) *TestFs {
|
||||||
dirs := map[string]bool{}
|
dirs := map[string]bool{}
|
||||||
for abs, _ := range files {
|
for abs, _ := range files {
|
||||||
for d := filepath.Dir(abs); !dirs[d]; d = filepath.Dir(d) {
|
for d := filepath.ToSlash(filepath.Dir(abs)); !dirs[d]; d = filepath.ToSlash(filepath.Dir(d)) {
|
||||||
dirs[d] = true
|
dirs[d] = true
|
||||||
fmt.Fprintf(os.Stderr, "testfs: recognized dir: %s\n", d)
|
fmt.Fprintf(os.Stderr, "testfs: recognized dir: %s\n", d)
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ func (f *TestFs) FileExistsAt(path string) bool {
|
||||||
if strings.HasPrefix(path, "/") {
|
if strings.HasPrefix(path, "/") {
|
||||||
_, ok = f.files[path]
|
_, ok = f.files[path]
|
||||||
} else {
|
} else {
|
||||||
_, ok = f.files[filepath.Join(f.Cwd, path)]
|
_, ok = f.files[filepath.ToSlash(filepath.Join(f.Cwd, path))]
|
||||||
}
|
}
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +56,7 @@ func (f *TestFs) DirectoryExistsAt(path string) bool {
|
||||||
if strings.HasPrefix(path, "/") {
|
if strings.HasPrefix(path, "/") {
|
||||||
_, ok = f.dirs[path]
|
_, ok = f.dirs[path]
|
||||||
} else {
|
} else {
|
||||||
_, ok = f.dirs[filepath.Join(f.Cwd, path)]
|
_, ok = f.dirs[filepath.ToSlash(filepath.Join(f.Cwd, path))]
|
||||||
}
|
}
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ func (f *TestFs) ReadFile(filename string) ([]byte, error) {
|
||||||
if strings.HasPrefix(filename, "/") {
|
if strings.HasPrefix(filename, "/") {
|
||||||
str, ok = f.files[filename]
|
str, ok = f.files[filename]
|
||||||
} else {
|
} else {
|
||||||
str, ok = f.files[filepath.Join(f.Cwd, filename)]
|
str, ok = f.files[filepath.ToSlash(filepath.Join(f.Cwd, filename))]
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
return []byte(nil), os.ErrNotExist
|
return []byte(nil), os.ErrNotExist
|
||||||
|
|
@ -93,7 +93,7 @@ func (f *TestFs) Glob(relPattern string) ([]string, error) {
|
||||||
if strings.HasPrefix(relPattern, "/") {
|
if strings.HasPrefix(relPattern, "/") {
|
||||||
pattern = relPattern
|
pattern = relPattern
|
||||||
} else {
|
} else {
|
||||||
pattern = filepath.Join(f.Cwd, relPattern)
|
pattern = filepath.ToSlash(filepath.Join(f.Cwd, relPattern))
|
||||||
}
|
}
|
||||||
|
|
||||||
fixtures, ok := f.GlobFixtures[pattern]
|
fixtures, ok := f.GlobFixtures[pattern]
|
||||||
|
|
@ -115,13 +115,14 @@ func (f *TestFs) Glob(relPattern string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TestFs) Abs(path string) (string, error) {
|
func (f *TestFs) Abs(path string) (string, error) {
|
||||||
|
path = filepath.ToSlash(path)
|
||||||
var p string
|
var p string
|
||||||
if strings.HasPrefix(path, "/") {
|
if strings.HasPrefix(path, "/") {
|
||||||
p = path
|
p = path
|
||||||
} else {
|
} else {
|
||||||
p = filepath.Join(f.Cwd, path)
|
p = filepath.Join(f.Cwd, path)
|
||||||
}
|
}
|
||||||
return filepath.Clean(p), nil
|
return filepath.ToSlash(filepath.Clean(p)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TestFs) Getwd() (string, error) {
|
func (f *TestFs) Getwd() (string, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue