From ad7ca2dffca81f88e5b206f730e99f9d8f1e918c Mon Sep 17 00:00:00 2001 From: David Dworken Date: Mon, 20 Nov 2023 21:00:37 -0800 Subject: [PATCH] Add additional check against hishtory export to help debug control-r test failures that only reproduce in github actions --- client/client_test.go | 6 ++++-- client/lib/goldens/testControlR-InitialExport | 5 +++++ client/testutils.go | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 client/lib/goldens/testControlR-InitialExport diff --git a/client/client_test.go b/client/client_test.go index 279536d..641bf26 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1970,15 +1970,17 @@ func testControlR(t *testing.T, tester shellTester, shellName string, onlineStat require.NoError(t, db.Create(testutils.MakeFakeHistoryEntry("echo 'aaaaaa bbbb'")).Error) require.NoError(t, db.Create(testutils.MakeFakeHistoryEntry("echo 'bar' &")).Error) - // Check that they're there + // Check that they're there (and there aren't any other entries) var historyEntries []*data.HistoryEntry db.Model(&data.HistoryEntry{}).Find(&historyEntries) if len(historyEntries) != 5 { t.Fatalf("expected to find 6 history entries, actual found %d: %#v", len(historyEntries), historyEntries) } + out := tester.RunInteractiveShell(t, `hishtory export`) + testutils.CompareGoldens(t, out, "testControlR-InitialExport") // And check that the control-r binding brings up the search - out := captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R"}) + out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R"}) split := strings.Split(out, "\n\n\n") out = strings.TrimSpace(split[len(split)-1]) testutils.CompareGoldens(t, out, "testControlR-Initial") diff --git a/client/lib/goldens/testControlR-InitialExport b/client/lib/goldens/testControlR-InitialExport new file mode 100644 index 0000000..62b99ef --- /dev/null +++ b/client/lib/goldens/testControlR-InitialExport @@ -0,0 +1,5 @@ +ls ~/ +ls ~/foo/ +ls ~/bar/ +echo 'aaaaaa bbbb' +echo 'bar' & diff --git a/client/testutils.go b/client/testutils.go index 972379e..41104f6 100644 --- a/client/testutils.go +++ b/client/testutils.go @@ -260,6 +260,7 @@ func captureTerminalOutputComplex(t testing.TB, captureConfig TmuxCaptureConfig) fullCommand += "\n" fullCommand += " tmux kill-session -t foo\n" testutils.TestLog(t, "Running tmux command: "+fullCommand) + // TODO: Can this use the strict version instead? out, err := captureConfig.tester.RunInteractiveShellRelaxed(t, fullCommand) require.NoError(t, err) return strings.TrimSpace(out)