diff --git a/tests/scripts/pwd/main.go b/tests/scripts/pwd/main.go new file mode 100644 index 00000000..020d1f2d --- /dev/null +++ b/tests/scripts/pwd/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + path, _ := os.Getwd() + fmt.Println("Current path:", path) + err := os.WriteFile("pwd.txt", []byte(path), 0600) + if err != nil { + fmt.Println("Could not write to pwd.txt:", err) + return + } + fmt.Println("Wrote to pwd.txt") +} diff --git a/tests/table_test.go b/tests/table_test.go index bdae93a6..32b09dd2 100644 --- a/tests/table_test.go +++ b/tests/table_test.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "runtime" "strings" "testing" "time" @@ -981,7 +982,7 @@ Repositories with a successful run: }, }, { - name: "custom clone dir", + name: "custom clone dir with relative path", vcCreate: func(t *testing.T) *vcmock.VersionController { return &vcmock.VersionController{ Repositories: []vcmock.Repository{ @@ -996,11 +997,55 @@ Repositories with a successful run: "-B", "clone-dir-branch-name", "-m", "clone dir message", "--clone-dir", "./tmp-test", - changerBinaryPath, + fmt.Sprintf("go run %s", normalizePath(filepath.Join(workingDir, "scripts/pwd/main.go"))), }, verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { require.Len(t, vcMock.PullRequests, 1) - assert.True(t, fileExist(t, workingDir, "tmp-test")) + expectedPath := filepath.Join(workingDir, "tmp-test") + + // Check the path in the logs + assert.Contains(t, runData.logOut, "Current path: "+strings.ReplaceAll(expectedPath, `\`, `\\`)) + + // Check the path in + changeBranch(t, vcMock.Repositories[0].Path, "clone-dir-branch-name", false) + pathInFile := readFile(t, vcMock.Repositories[0].Path, "pwd.txt") + assert.True(t, strings.HasPrefix(pathInFile, expectedPath)) + }, + }, + { + name: "custom clone dir with absolute path", + vcCreate: func(t *testing.T) *vcmock.VersionController { + return &vcmock.VersionController{ + Repositories: []vcmock.Repository{ + createRepo(t, "owner", "should-change", "i like apples"), + }, + } + }, + args: []string{ + "run", + "--author-name", "Test Author", + "--author-email", "test@example.com", + "-B", "clone-dir-branch-name", + "-m", "clone dir message", + "--clone-dir", filepath.Join(os.TempDir(), "tmp-test"), + fmt.Sprintf("go run %s", normalizePath(filepath.Join(workingDir, "scripts/pwd/main.go"))), + }, + verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { + require.Len(t, vcMock.PullRequests, 1) + + tmpDir := os.TempDir() + // Fix for MacOS (darwin) where the tmp directory is aliased under two different directories + if runtime.GOOS == "darwin" { + tmpDir = filepath.Join("/private", tmpDir) + } + + expectedPath := filepath.Join(tmpDir, "tmp-test") + + assert.Contains(t, runData.logOut, "Current path: "+strings.ReplaceAll(expectedPath, `\`, `\\`)) + + changeBranch(t, vcMock.Repositories[0].Path, "clone-dir-branch-name", false) + pathInFile := readFile(t, vcMock.Repositories[0].Path, "pwd.txt") + assert.True(t, strings.HasPrefix(pathInFile, expectedPath)) }, }, }