diff --git a/client/client_test.go b/client/client_test.go index 1aab972..c99f49c 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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 { diff --git a/client/lib/goldens/testDisplayTable-customColumns-trulyCustom b/client/lib/goldens/testDisplayTable-customColumns-trulyCustom index b77b658..e3fab00 100644 --- a/client/lib/goldens/testDisplayTable-customColumns-trulyCustom +++ b/client/lib/goldens/testDisplayTable-customColumns-trulyCustom @@ -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 diff --git a/shared/testutils/testutils.go b/shared/testutils/testutils.go index aabf612..71533ad 100644 --- a/shared/testutils/testutils.go +++ b/shared/testutils/testutils.go @@ -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)) } }