mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Chdir so that we have a consistent cwd for github actions
This commit is contained in:
parent
189f183d69
commit
0f9e77223e
@ -29,6 +29,8 @@ func skipSlowTests() bool {
|
||||
return os.Getenv("FAST") != ""
|
||||
}
|
||||
|
||||
var initialWd string
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
defer testutils.RunTestServer()()
|
||||
cmd := exec.Command("go", "build", "-o", "/tmp/client")
|
||||
@ -38,6 +40,11 @@ func TestMain(m *testing.M) {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to build client: %v", err))
|
||||
}
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to os.Getwd(): %v", err))
|
||||
}
|
||||
initialWd = cwd
|
||||
m.Run()
|
||||
}
|
||||
|
||||
@ -1020,6 +1027,7 @@ func testDisplayTable(t *testing.T, tester shellTester) {
|
||||
|
||||
// Add a custom column
|
||||
tester.RunInteractiveShell(t, `hishtory config-add custom-columns foo "echo aaaaaaaaaaaaa"`)
|
||||
testutils.Check(t, os.Chdir("/"))
|
||||
tester.RunInteractiveShell(t, ` hishtory enable`)
|
||||
tester.RunInteractiveShell(t, `echo table-1`)
|
||||
tester.RunInteractiveShell(t, `echo table-2`)
|
||||
@ -1734,7 +1742,7 @@ func normalizeHostnames(data string) string {
|
||||
|
||||
func compareGoldens(t *testing.T, out, goldenName string) {
|
||||
out = normalizeHostnames(out)
|
||||
goldenPath := path.Join("client/lib/goldens/", goldenName)
|
||||
goldenPath := path.Join(initialWd, "client/lib/goldens/", goldenName)
|
||||
expected, err := os.ReadFile(goldenPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@ -1938,7 +1946,10 @@ func testControlR(t *testing.T, tester shellTester, shellName string) {
|
||||
if strings.Contains(out, "Search Query") || strings.Contains(out, "─────") || strings.Contains(out, "Exit Code") {
|
||||
t.Fatalf("hishtory overrode control-r even when this was disabled? out=%#v", out)
|
||||
}
|
||||
compareGoldens(t, out, "testControlR-"+shellName+"-Disabled")
|
||||
if os.Getenv("GITHUB_ACTION") == "" {
|
||||
// This bit is broken on actions since actions run as a different user
|
||||
compareGoldens(t, out, "testControlR-"+shellName+"-Disabled")
|
||||
}
|
||||
}
|
||||
|
||||
type deviceSet struct {
|
||||
|
@ -1,6 +1,6 @@
|
||||
Hostname Exit Code Command CWD foo
|
||||
ghaction-runner-hostname 0 echo table-2 ~/code/hishtory aaaaaaaaaaaaa
|
||||
ghaction-runner-hostname 0 echo table-1 ~/code/hishtory aaaaaaaaaaaaa
|
||||
ghaction-runner-hostname 0 echo table-2 / aaaaaaaaaaaaa
|
||||
ghaction-runner-hostname 0 echo table-1 / aaaaaaaaaaaaa
|
||||
ghaction-runner-hostname 0 hishtory query table ~/code/hishtory
|
||||
localhost 2 while : /tmp/
|
||||
do
|
||||
|
@ -59,9 +59,9 @@ func DeleteBakFiles(t *testing.T) {
|
||||
func BackupAndRestoreWithId(t *testing.T, id string) func() {
|
||||
ResetFakeHistoryTimestamp()
|
||||
homedir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to retrieve homedir: %v", err)
|
||||
}
|
||||
Check(t, err)
|
||||
initialWd, err := os.Getwd()
|
||||
Check(t, err)
|
||||
|
||||
renameFiles := []string{
|
||||
path.Join(homedir, data.HISHTORY_PATH, data.DB_PATH),
|
||||
@ -102,6 +102,7 @@ func BackupAndRestoreWithId(t *testing.T, id string) func() {
|
||||
if err != nil && err.Error() != "exit status 1" {
|
||||
t.Fatalf("failed to execute killall hishtory, stdout=%#v: %v", string(stdout), err)
|
||||
}
|
||||
checkError(os.Chdir(initialWd))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user