Improve testPresaving to cover more potential errors with presaving

This commit is contained in:
David Dworken 2023-09-24 16:35:40 -07:00
parent 0db27d4217
commit 354f2872d6
No known key found for this signature in database

View File

@ -2051,11 +2051,9 @@ func testPresaving(t *testing.T, tester shellTester) {
manuallySubmitHistoryEntry(t, userSecret, testutils.MakeFakeHistoryEntry("table_sizing aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) manuallySubmitHistoryEntry(t, userSecret, testutils.MakeFakeHistoryEntry("table_sizing aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
// Enable beta-mode since presaving is behind that feature flag // Enable beta-mode since presaving is behind that feature flag
out := strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)) require.Equal(t, "false", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)))
require.Equal(t, out, "false")
tester.RunInteractiveShell(t, `hishtory config-set beta-mode true`) tester.RunInteractiveShell(t, `hishtory config-set beta-mode true`)
out = strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)) require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)))
require.Equal(t, out, "true")
// Start a command that will take a long time to execute in the background, so // Start a command that will take a long time to execute in the background, so
// we can check that it was recorded even though it never finished. // we can check that it was recorded even though it never finished.
@ -2064,7 +2062,7 @@ func testPresaving(t *testing.T, tester shellTester) {
time.Sleep(time.Millisecond * 500) time.Sleep(time.Millisecond * 500)
// Test that it shows up in hishtory export // Test that it shows up in hishtory export
out = tester.RunInteractiveShell(t, ` hishtory export sleep -export`) out := tester.RunInteractiveShell(t, ` hishtory export sleep -export`)
expectedOutput := "sleep 13371337\n" expectedOutput := "sleep 13371337\n"
if diff := cmp.Diff(expectedOutput, out); diff != "" { if diff := cmp.Diff(expectedOutput, out); diff != "" {
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out) t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
@ -2075,6 +2073,16 @@ func testPresaving(t *testing.T, tester shellTester) {
out = tester.RunInteractiveShell(t, ` hishtory query sleep 13371337 -export -tquery`) out = tester.RunInteractiveShell(t, ` hishtory query sleep 13371337 -export -tquery`)
testutils.CompareGoldens(t, out, "testPresaving-query") testutils.CompareGoldens(t, out, "testPresaving-query")
// And then record a few other commands, and run an export of all commands, to ensure no funkiness happened
tester.RunInteractiveShell(t, `ls /`)
time.Sleep(time.Second)
tester.RunInteractiveShell(t, `sleep 0.5`)
out = tester.RunInteractiveShell(t, ` hishtory export -hishtory -table_sizing -pipefail`)
expectedOutput = "sleep 13371337\nls /\nsleep 0.5\n"
if diff := cmp.Diff(expectedOutput, out); diff != "" {
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
}
// Create a new device, and confirm it shows up there too // Create a new device, and confirm it shows up there too
restoreDevice1 := testutils.BackupAndRestoreWithId(t, "device1") restoreDevice1 := testutils.BackupAndRestoreWithId(t, "device1")
installHishtory(t, tester, userSecret) installHishtory(t, tester, userSecret)
@ -2087,12 +2095,19 @@ func testPresaving(t *testing.T, tester shellTester) {
// And confirm it was redacted // And confirm it was redacted
out = tester.RunInteractiveShell(t, ` hishtory export sleep -export`) out = tester.RunInteractiveShell(t, ` hishtory export sleep -export`)
require.Equal(t, "", out) require.Equal(t, "sleep 0.5\n", out)
// Then go back to device1 and confirm it was redacted there too // Then go back to device1 and confirm it was redacted there too
restoreDevice1() restoreDevice1()
out = tester.RunInteractiveShell(t, ` hishtory export sleep -export`) out = tester.RunInteractiveShell(t, ` hishtory export sleep -export`)
require.Equal(t, "", out) require.Equal(t, "sleep 0.5\n", out)
// And then record a few commands, and run a final export of all commands, to ensure no funkiness happened
out = tester.RunInteractiveShell(t, ` hishtory export -hishtory -table_sizing -pipefail`)
expectedOutput = "ls /\nsleep 0.5\n"
if diff := cmp.Diff(expectedOutput, out); diff != "" {
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
}
} }
func testUninstall(t *testing.T, tester shellTester) { func testUninstall(t *testing.T, tester shellTester) {
@ -2291,7 +2306,7 @@ func TestSetConfigNoCorruption(t *testing.T) {
c.DeviceId = strings.Repeat("B", i*2) c.DeviceId = strings.Repeat("B", i*2)
c.HaveMissedUploads = (i % 2) == 0 c.HaveMissedUploads = (i % 2) == 0
// Write it // Write it
err := hctx.SetConfig(&c) require.NoError(t, hctx.SetConfig(&c))
require.NoError(t, err) require.NoError(t, err)
// Check that we can read // Check that we can read
c2, err := hctx.GetConfig() c2, err := hctx.GetConfig()