diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 6378fbc..2a2278d 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -34,23 +34,15 @@ jobs: # Set a consistent hostname so we can run tests that depend on it sudo hostname ghaction-runner-hostname - - # Set up a tmpfs for ~/.hishtory/ to help tests run faster - mkdir ~/.hishtory/ - sudo mount -t tmpfs -o size=500M hishtory-tmpfs ~/.hishtory/ - name: MacOS Setup if: ${{ !startsWith(github.event.head_commit.message, 'Release') && matrix.os == 'macos-latest'}} run: | # Install our dependencies - brew install fish tmux bash + brew install fish tmux bash # Set a consistent hostname so we can run tests that depend on it - sudo scutil --set HostName ghaction-runner-hostname - - # Set up a tmpfs for ~/.hishtory/ to help tests run faster - sudo diskutil apfs create $(sudo hdiutil attach -nomount ram://1024000) tmpfs - ln -s /Volumes/tmpfs ~/.hishtory + sudo scutil --set HostName ghaction-runner-hostname - name: Go test if: ${{ !startsWith(github.event.head_commit.message, 'Release') }} run: | diff --git a/Makefile b/Makefile index 6c5282f..22f379a 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ forcetest: go clean -testcache - TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 go test -p 1 -timeout 90m ./... + TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 go test -p 1 -timeout 45m ./... test: - TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 go test -p 1 -timeout 90m ./... + TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 go test -p 1 -timeout 45m ./... ftest: go clean -testcache diff --git a/shared/testutils/testutils.go b/shared/testutils/testutils.go index 211dace..4ad1247 100644 --- a/shared/testutils/testutils.go +++ b/shared/testutils/testutils.go @@ -47,8 +47,11 @@ func getInitialWd() string { } func ResetLocalState(t *testing.T) { + homedir, err := os.UserHomeDir() + Check(t, err) persistLog() _ = BackupAndRestoreWithId(t, "-reset-local-state") + _ = os.RemoveAll(path.Join(homedir, data.GetHishtoryPath())) } func BackupAndRestore(t testing.TB) func() { @@ -85,7 +88,7 @@ func BackupAndRestoreWithId(t testing.TB, id string) func() { } for _, file := range renameFiles { touchFile(file) - Check(t, rename(file, getBackPath(file, id))) + Check(t, os.Rename(file, getBackPath(file, id))) } copyFiles := []string{ path.Join(homedir, ".zshrc"), @@ -107,14 +110,10 @@ func BackupAndRestoreWithId(t testing.TB, id string) func() { t.Fatalf("failed to execute killall hishtory, stdout=%#v: %v", string(stdout), err) } persistLog() - for _, file := range renameFiles { - if strings.Contains(file, data.GetHishtoryPath()) { - _ = os.Remove(file) - } - } + Check(t, os.RemoveAll(path.Join(homedir, data.GetHishtoryPath()))) Check(t, os.MkdirAll(path.Join(homedir, data.GetHishtoryPath()), os.ModePerm)) for _, file := range renameFiles { - checkError(rename(getBackPath(file, id), file)) + checkError(os.Rename(getBackPath(file, id), file)) } for _, file := range copyFiles { checkError(copy(getBackPath(file, id), file)) @@ -155,15 +154,6 @@ setopt SHARE_HISTORY checkError(err) } -// Similar to os.Rename, except it supports renaming cross-mount -func rename(src, dst string) error { - err := copy(src, dst) - if err != nil { - return err - } - return os.Remove(src) -} - func copy(src, dst string) error { // Copy the contents of the file in, err := os.Open(src)