Skip to content

Commit

Permalink
just a test commit to check how --clone-dir can be tested
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Jul 22, 2023
1 parent cd23524 commit e5f0c90
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tests/scripts/pwd/main.go
Original file line number Diff line number Diff line change
@@ -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")
}
51 changes: 48 additions & 3 deletions tests/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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{
Expand All @@ -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))
},
},
}
Expand Down

0 comments on commit e5f0c90

Please sign in to comment.