mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Fix tests for importing so they pass on github actions
This commit is contained in:
parent
80f0660ade
commit
55f0f97d29
1
.github/workflows/go-test.yml
vendored
1
.github/workflows/go-test.yml
vendored
@ -25,5 +25,4 @@ jobs:
|
||||
run: |
|
||||
sudo apt-get update || true
|
||||
sudo apt-get install -y zsh || true
|
||||
export HISTFILE=~/.zsh_history
|
||||
make test
|
||||
|
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ test:
|
||||
HISHTORY_TEST=1 go test -p 1 ./...
|
||||
|
||||
acttest:
|
||||
act push -j test -e .github/push_event.json --reuse
|
||||
act push -j test -e .github/push_event.json --reuse --container-architecture linux/amd64
|
||||
|
||||
release:
|
||||
# Bump the version
|
||||
|
@ -94,7 +94,7 @@ func (z zshTester) RunInteractiveShellRelaxed(t *testing.T, script string) (stri
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unexpected error when running command=%#v, out=%#v, err=%#v: %v", script, stdout.String(), stderr.String(), err)
|
||||
return stdout.String(), fmt.Errorf("unexpected error when running command=%#v, out=%#v, err=%#v: %v", script, stdout.String(), stderr.String(), err)
|
||||
}
|
||||
outStr := stdout.String()
|
||||
if strings.Contains(outStr, "hishtory fatal error") {
|
||||
@ -313,7 +313,7 @@ echo thisisrecorded`)
|
||||
// Test the actual table output
|
||||
hostnameMatcher := `\S+`
|
||||
tableDividerMatcher := `\s+`
|
||||
pathMatcher := `~/[a-zA-Z_0-9/-]+`
|
||||
pathMatcher := `~?/[a-zA-Z_0-9/-]+`
|
||||
datetimeMatcher := `[a-zA-Z]{3}\s\d{2}\s\d{4}\s[0-9:]+\s[A-Z]{3}`
|
||||
runtimeMatcher := `[0-9.ms]+`
|
||||
exitCodeMatcher := `0`
|
||||
|
@ -3,6 +3,7 @@ package shared
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -50,6 +51,25 @@ func BackupAndRestoreWithId(t *testing.T, id string) func() {
|
||||
_ = os.Rename(path.Join(homedir, HISHTORY_PATH, "hishtory"), path.Join(homedir, HISHTORY_PATH, "hishtory"+id+".bak"))
|
||||
_ = os.Rename(path.Join(homedir, HISHTORY_PATH, "config.sh"), path.Join(homedir, HISHTORY_PATH, "config.sh"+id+".bak"))
|
||||
_ = os.Rename(path.Join(homedir, HISHTORY_PATH, "config.zsh"), path.Join(homedir, HISHTORY_PATH, "config.zsh"+id+".bak"))
|
||||
_ = copy(path.Join(homedir, ".zshrc"), path.Join(homedir, ".zshrc"+id+".bak"))
|
||||
f, err := os.OpenFile(path.Join(homedir, ".zshrc"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
checkError(err)
|
||||
defer f.Close()
|
||||
_, err = f.WriteString(`export HISTFILE=~/.zsh_history
|
||||
export HISTSIZE=10000
|
||||
export SAVEHIST=1000
|
||||
setopt SHARE_HISTORY`)
|
||||
checkError(err)
|
||||
|
||||
_ = copy(path.Join(homedir, ".bashrc"), path.Join(homedir, ".bashrc"+id+".bak"))
|
||||
_ = os.Rename(path.Join(homedir, ".bash_history"), path.Join(homedir, ".bash_history"+id+".bak"))
|
||||
file, err := os.Create(path.Join(homedir, ".bash_history"))
|
||||
checkError(err)
|
||||
defer file.Close()
|
||||
_ = os.Rename(path.Join(homedir, ".zsh_history"), path.Join(homedir, ".zsh_history"+id+".bak"))
|
||||
file, err = os.Create(path.Join(homedir, ".zsh_history"))
|
||||
checkError(err)
|
||||
defer file.Close()
|
||||
return func() {
|
||||
checkError(os.Rename(path.Join(homedir, HISHTORY_PATH, DB_PATH+id+".bak"), path.Join(homedir, HISHTORY_PATH, DB_PATH)))
|
||||
checkError(os.Rename(path.Join(homedir, HISHTORY_PATH, DB_WAL_PATH+id+".bak"), path.Join(homedir, HISHTORY_PATH, DB_WAL_PATH)))
|
||||
@ -58,9 +78,33 @@ func BackupAndRestoreWithId(t *testing.T, id string) func() {
|
||||
checkError(os.Rename(path.Join(homedir, HISHTORY_PATH, "hishtory"+id+".bak"), path.Join(homedir, HISHTORY_PATH, "hishtory")))
|
||||
checkError(os.Rename(path.Join(homedir, HISHTORY_PATH, "config.sh"+id+".bak"), path.Join(homedir, HISHTORY_PATH, "config.sh")))
|
||||
checkError(os.Rename(path.Join(homedir, HISHTORY_PATH, "config.zsh"+id+".bak"), path.Join(homedir, HISHTORY_PATH, "config.zsh")))
|
||||
checkError(copy(path.Join(homedir, ".zshrc"+id+".bak"), path.Join(homedir, ".zshrc")))
|
||||
checkError(copy(path.Join(homedir, ".bashrc"+id+".bak"), path.Join(homedir, ".bashrc")))
|
||||
checkError(os.Rename(path.Join(homedir, ".bash_history"+id+".bak"), path.Join(homedir, ".bash_history")))
|
||||
checkError(os.Rename(path.Join(homedir, ".zsh_history"+id+".bak"), path.Join(homedir, ".zsh_history")))
|
||||
}
|
||||
}
|
||||
|
||||
func copy(src, dst string) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Close()
|
||||
}
|
||||
|
||||
func BackupAndRestoreEnv(k string) func() {
|
||||
origValue := os.Getenv(k)
|
||||
return func() {
|
||||
|
Loading…
Reference in New Issue
Block a user