From ded0f1049a4fedc9d0e103b895db6e4b5a859381 Mon Sep 17 00:00:00 2001 From: Quan TRAN Date: Sun, 2 May 2021 02:22:25 +0200 Subject: [PATCH] Fix filepath handling on Windows (#1754) --- pkg/app/app_test.go | 2 +- pkg/testhelper/testfs.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index d66b2e18..26c3ac3e 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -1522,7 +1522,7 @@ func TestLoadDesiredStateFromYaml_DuplicateReleaseName(t *testing.T) { stage: post `) readFile := func(filename string) ([]byte, error) { - if filename != yamlFile { + if filepath.ToSlash(filename) != yamlFile { return nil, fmt.Errorf("unexpected filename: %s", filename) } return yamlContent, nil diff --git a/pkg/testhelper/testfs.go b/pkg/testhelper/testfs.go index 90b58842..41a7d9ca 100644 --- a/pkg/testhelper/testfs.go +++ b/pkg/testhelper/testfs.go @@ -21,7 +21,7 @@ type TestFs struct { func NewTestFs(files map[string]string) *TestFs { dirs := map[string]bool{} 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 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, "/") { _, ok = f.files[path] } else { - _, ok = f.files[filepath.Join(f.Cwd, path)] + _, ok = f.files[filepath.ToSlash(filepath.Join(f.Cwd, path))] } return ok } @@ -56,7 +56,7 @@ func (f *TestFs) DirectoryExistsAt(path string) bool { if strings.HasPrefix(path, "/") { _, ok = f.dirs[path] } else { - _, ok = f.dirs[filepath.Join(f.Cwd, path)] + _, ok = f.dirs[filepath.ToSlash(filepath.Join(f.Cwd, path))] } return ok } @@ -67,7 +67,7 @@ func (f *TestFs) ReadFile(filename string) ([]byte, error) { if strings.HasPrefix(filename, "/") { str, ok = f.files[filename] } else { - str, ok = f.files[filepath.Join(f.Cwd, filename)] + str, ok = f.files[filepath.ToSlash(filepath.Join(f.Cwd, filename))] } if !ok { return []byte(nil), os.ErrNotExist @@ -93,7 +93,7 @@ func (f *TestFs) Glob(relPattern string) ([]string, error) { if strings.HasPrefix(relPattern, "/") { pattern = relPattern } else { - pattern = filepath.Join(f.Cwd, relPattern) + pattern = filepath.ToSlash(filepath.Join(f.Cwd, relPattern)) } 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) { + path = filepath.ToSlash(path) var p string if strings.HasPrefix(path, "/") { p = path } else { p = filepath.Join(f.Cwd, path) } - return filepath.Clean(p), nil + return filepath.ToSlash(filepath.Clean(p)), nil } func (f *TestFs) Getwd() (string, error) {