Fix more tests for presaving

This commit is contained in:
David Dworken 2023-11-19 08:56:02 -08:00
parent 223bb1754d
commit a99747602e
No known key found for this signature in database
6 changed files with 22 additions and 19 deletions

View File

@ -128,10 +128,8 @@ func testIntegrationWithNewDevice(t *testing.T, tester shellTester) {
// Run the test
userSecret := testBasicUserFlow(t, tester, Online)
// Clear all local state
testutils.ResetLocalState(t)
// Install it again
testutils.ResetLocalState(t)
installHishtory(t, tester, userSecret)
// Querying should show the history from the previous run
@ -151,16 +149,16 @@ func testIntegrationWithNewDevice(t *testing.T, tester shellTester) {
t.Fatalf("output has `echo mynewcommand` the wrong number of times")
}
// Clear local state again
testutils.ResetLocalState(t)
// Install it a 3rd time
testutils.ResetLocalState(t)
installHishtory(t, tester, "adifferentsecret")
// Run a command that shouldn't be in the hishtory later on
tester.RunInteractiveShell(t, `echo notinthehistory`)
out = hishtoryQuery(t, tester, "")
require.Contains(t, out, "echo notinthehistory")
require.NotContains(t, out, "mynewcommand")
require.NotContains(t, out, "thisisrecorded")
// Set the secret key to the previous secret key
out, err := tester.RunInteractiveShellRelaxed(t, ` export HISHTORY_SKIP_INIT_IMPORT=1
@ -206,7 +204,7 @@ yes | hishtory init `+userSecret)
// Finally, test the export command
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail | grep -v '/tmp/client install'`)
require.NotContains(t, out, "thisisnotrecorded", "hishtory export contains a command that should not have been recorded")
expectedOutputWithoutKey := "hishtory status\nhishtory query\nls /a\nls /bar\nls /foo\necho foo\necho bar\nhishtory enable\necho thisisrecorded\nhishtory query\nhishtory query foo\necho hello | grep complex | sed s/h/i/g; echo baz && echo \"fo 'o\" # mycommand\nhishtory query complex\nhishtory query\necho mynewcommand\nhishtory query\nyes | hishtory init %s\nhishtory query\necho mynewercommand\nhishtory query\nothercomputer\nhishtory query\nhishtory reupload\n"
expectedOutputWithoutKey := "hishtory status\nhishtory query\nls /a\nls /bar\nls /foo\necho foo\necho bar\nhishtory disable\nhishtory enable\necho thisisrecorded\nhishtory query\nhishtory query foo\necho hello | grep complex | sed s/h/i/g; echo baz && echo \"fo 'o\" # mycommand\nhishtory query complex\nhishtory query\necho mynewcommand\nhishtory query\nyes | hishtory init %s\nhishtory query\necho mynewercommand\nhishtory query\nothercomputer\nhishtory query\nhishtory reupload\n"
expectedOutput := fmt.Sprintf(expectedOutputWithoutKey, userSecret)
if diff := cmp.Diff(expectedOutput, out); diff != "" {
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
@ -2625,3 +2623,4 @@ func TestAugmentedIsOfflineError(t *testing.T) {
}
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed
// TODO: Tests for deleting presaved entries while offline

View File

@ -1,9 +1,9 @@
CWD Hostname Exit Code Command
/ ghaction-runner-hostname 0 hishtory config-set displayed-columns CWD Hostname 'Exit Code' Command
/ ghaction-runner-hostname 0 exit
/ ghaction-runner-hostname 0 echo foo
/ ghaction-runner-hostname 0 fish
/ ghaction-runner-hostname 0 ls /tmp/ &
/ ghaction-runner-hostname 0 echo "foo"
/ ghaction-runner-hostname 0 echo bar
/ ghaction-runner-hostname 0 echo foo
/ ghaction-runner-hostname 0 hishtory config-set displayed-columns CWD Hostname 'Exit Code' Command
/ ghaction-runner-hostname 0 exit
/ ghaction-runner-hostname 0 echo foo
/ ghaction-runner-hostname 0 fish
/ ghaction-runner-hostname 0 ls /tmp/ &
/ ghaction-runner-hostname 0 echo "foo"
/ ghaction-runner-hostname 0 echo bar
/ ghaction-runner-hostname 0 echo foo

View File

@ -5,6 +5,7 @@ ls /bar
ls /foo
echo foo
echo bar
hishtory disable
hishtory enable
echo thisisrecorded
hishtory query

View File

@ -1,8 +1,8 @@
Hostname Exit Code Command
Hostname Exit Code Command
ghaction-runner-hostname 0 hishtory config-set displayed-columns Hostname 'Exit Code' Command
ghaction-runner-hostname 0 hishtory reupload
ghaction-runner-hostname 0 hishtory query
localhost 2 othercomputer
localhost 2 othercomputer
ghaction-runner-hostname 0 hishtory query
ghaction-runner-hostname 0 echo mynewercommand
ghaction-runner-hostname 0 hishtory query
@ -15,6 +15,7 @@ ghaction-runner-hostname 0 hishtory query foo
ghaction-runner-hostname 0 hishtory query
ghaction-runner-hostname 0 echo thisisrecorded
ghaction-runner-hostname 0 hishtory enable
ghaction-runner-hostname 0 hishtory disable
ghaction-runner-hostname 0 echo bar
ghaction-runner-hostname 0 echo foo
ghaction-runner-hostname 0 hishtory query

View File

@ -1,8 +1,8 @@
Hostname Exit Code Command
Hostname Exit Code Command
ghaction-runner-hostname 0 hishtory config-set displayed-columns Hostname 'Exit Code' Command
ghaction-runner-hostname 0 hishtory reupload
ghaction-runner-hostname 0 hishtory query
localhost 2 othercomputer
localhost 2 othercomputer
ghaction-runner-hostname 0 hishtory query
ghaction-runner-hostname 0 echo mynewercommand
ghaction-runner-hostname 0 hishtory query
@ -15,6 +15,7 @@ ghaction-runner-hostname 0 hishtory query foo
ghaction-runner-hostname 0 hishtory query
ghaction-runner-hostname 0 echo thisisrecorded
ghaction-runner-hostname 0 hishtory enable
ghaction-runner-hostname 0 hishtory disable
ghaction-runner-hostname 0 echo bar
ghaction-runner-hostname 0 echo foo
ghaction-runner-hostname 0 hishtory query

View File

@ -5,6 +5,7 @@ ls /bar
ls /foo
echo foo
echo bar
hishtory disable
hishtory enable
echo thisisrecorded
hishtory query