Skip to content

Commit

Permalink
test: fixed so that tests run even if there is a space in the path of (
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell authored Nov 14, 2022
1 parent 9134e08 commit e387429
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/repo_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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), " ", "\\ ")
}
2 changes: 1 addition & 1 deletion tests/story_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions tests/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestTable(t *testing.T) {
"--author-email", "[email protected]",
"-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)
Expand Down Expand Up @@ -546,7 +546,7 @@ Repositories with a successful run:
"--author-email", "[email protected]",
"-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)
Expand All @@ -573,7 +573,7 @@ Repositories with a successful run:
"--author-email", "[email protected]",
"-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)
Expand Down Expand Up @@ -920,7 +920,7 @@ Repositories with a successful run:
"--author-email", "[email protected]",
"-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)
Expand Down

0 comments on commit e387429

Please sign in to comment.