Fix test failures caused by the cobra install command not respecting the secret key

Also added a persistLog() function so that I can easily inspect the hishtory logs from test runs.
This commit is contained in:
David Dworken
2022-11-16 20:28:25 -08:00
parent 35208680d8
commit 86f9d67aff
4 changed files with 30 additions and 9 deletions

View File

@ -25,10 +25,8 @@ const (
func ResetLocalState(t *testing.T) {
homedir, err := os.UserHomeDir()
if err != nil {
t.Fatalf("failed to retrieve homedir: %v", err)
}
Check(t, err)
persistLog()
_ = BackupAndRestoreWithId(t, "-reset-local-state")
_ = os.RemoveAll(path.Join(homedir, data.HISHTORY_PATH))
}
@ -90,6 +88,7 @@ func BackupAndRestoreWithId(t *testing.T, id string) func() {
t.Fatalf("failed to execute killall hishtory, stdout=%#v: %v", string(stdout), err)
}
}
persistLog()
Check(t, os.RemoveAll(path.Join(homedir, data.HISHTORY_PATH)))
Check(t, os.MkdirAll(path.Join(homedir, data.HISHTORY_PATH), os.ModePerm))
for _, file := range renameFiles {
@ -298,3 +297,20 @@ func TestLog(t *testing.T, line string) {
Check(t, err)
}
}
func persistLog() {
homedir, err := os.UserHomeDir()
checkError(err)
fp := path.Join(homedir, data.HISHTORY_PATH, "hishtory.log")
log, err := os.ReadFile(fp)
if err != nil {
return
}
f, err := os.OpenFile("/tmp/hishtory.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
checkError(err)
defer f.Close()
_, err = f.Write(log)
checkError(err)
_, err = f.WriteString("\n")
checkError(err)
}