From e387429d99ce3b2272a11a91b8f917598ce5f4a3 Mon Sep 17 00:00:00 2001 From: Johan Lindell Date: Mon, 14 Nov 2022 19:38:56 +0100 Subject: [PATCH] test: fixed so that tests run even if there is a space in the path of (#305) --- tests/print_test.go | 2 +- tests/repo_helper_test.go | 5 +++++ tests/story_test.go | 2 +- tests/table_test.go | 10 +++++----- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/print_test.go b/tests/print_test.go index b9b551f6..109d52cc 100644 --- a/tests/print_test.go +++ b/tests/print_test.go @@ -39,7 +39,7 @@ func TestPrint(t *testing.T) { "--log-file", filepath.ToSlash(runLogFile), "--output", filepath.ToSlash(outFile), "--error-output", filepath.ToSlash(errOutFile), - fmt.Sprintf(`go run %s`, filepath.ToSlash(filepath.Join(workingDir, "scripts/printer/main.go"))), + fmt.Sprintf(`go run %s`, normalizePath(filepath.Join(workingDir, "scripts/printer/main.go"))), }) err = command.Execute() assert.NoError(t, err) diff --git a/tests/repo_helper_test.go b/tests/repo_helper_test.go index 8fed435a..8968d3fd 100644 --- a/tests/repo_helper_test.go +++ b/tests/repo_helper_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" "time" @@ -173,3 +174,7 @@ func fileExist(t *testing.T, basePath string, fn string) bool { require.NoError(t, err) return true } + +func normalizePath(path string) string { + return strings.ReplaceAll(filepath.ToSlash(path), " ", "\\ ") +} diff --git a/tests/story_test.go b/tests/story_test.go index 8f298994..818f2448 100644 --- a/tests/story_test.go +++ b/tests/story_test.go @@ -25,7 +25,7 @@ func TestStory(t *testing.T) { workingDir, err := os.Getwd() assert.NoError(t, err) - changerBinaryPath := filepath.ToSlash(filepath.Join(workingDir, changerBinaryPath)) + changerBinaryPath := normalizePath(filepath.Join(workingDir, changerBinaryPath)) changeRepo := createRepo(t, "owner", "should-change", "i like apples") changeRepo2 := createRepo(t, "owner", "should-change-2", "i like my apple") diff --git a/tests/table_test.go b/tests/table_test.go index 69ce932c..a3b33682 100644 --- a/tests/table_test.go +++ b/tests/table_test.go @@ -72,7 +72,7 @@ func TestTable(t *testing.T) { workingDir, err := os.Getwd() assert.NoError(t, err) - changerBinaryPath := filepath.ToSlash(filepath.Join(workingDir, changerBinaryPath)) + changerBinaryPath := normalizePath(filepath.Join(workingDir, changerBinaryPath)) tests := []struct { name string @@ -135,7 +135,7 @@ func TestTable(t *testing.T) { "--author-email", "test@example.com", "-B", "custom-branch-name", "-m", "custom message", - fmt.Sprintf("go run %s", filepath.ToSlash(filepath.Join(workingDir, "scripts/changer/main.go"))), + fmt.Sprintf("go run %s", normalizePath(filepath.Join(workingDir, "scripts/changer/main.go"))), }, verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { require.Len(t, vcMock.PullRequests, 1) @@ -546,7 +546,7 @@ Repositories with a successful run: "--author-email", "test@example.com", "-B", "custom-branch-name", "-m", "custom message", - fmt.Sprintf("go run %s -filenames node_modules/react/README.md,src/index.js -data test", filepath.ToSlash(filepath.Join(workingDir, "scripts/adder/main.go"))), + fmt.Sprintf("go run %s -filenames node_modules/react/README.md,src/index.js -data test", normalizePath(filepath.Join(workingDir, "scripts/adder/main.go"))), }, verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { require.Len(t, vcMock.PullRequests, 1) @@ -573,7 +573,7 @@ Repositories with a successful run: "--author-email", "test@example.com", "-B", "custom-branch-name", "-m", "custom message", - fmt.Sprintf("go run %s -filenames node_modules/react/README.md,src/index.js -data test", filepath.ToSlash(filepath.Join(workingDir, "scripts/adder/main.go"))), + fmt.Sprintf("go run %s -filenames node_modules/react/README.md,src/index.js -data test", normalizePath(filepath.Join(workingDir, "scripts/adder/main.go"))), }, verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { require.Len(t, vcMock.PullRequests, 1) @@ -920,7 +920,7 @@ Repositories with a successful run: "--author-email", "test@example.com", "-B", "custom-branch-name", "-m", "custom message", - fmt.Sprintf("go run %s", filepath.ToSlash(filepath.Join(workingDir, "scripts/remover/main.go"))), + fmt.Sprintf("go run %s", normalizePath(filepath.Join(workingDir, "scripts/remover/main.go"))), }, verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { require.Len(t, vcMock.PullRequests, 1)