MCPcopy
hub / github.com/ddworken/hishtory / testRepeatedCommandThenQuery

Function testRepeatedCommandThenQuery

client/integration_test.go:639–677  ·  view source on GitHub ↗
(t *testing.T, tester shellTester)

Source from the content-addressed store, hash-verified

637}
638
639func testRepeatedCommandThenQuery(t *testing.T, tester shellTester) {
640 // Set up
641 defer testutils.BackupAndRestore(t)()
642 userSecret := installHishtory(t, tester, "")
643
644 // Check the status command
645 out := tester.RunInteractiveShell(t, `hishtory status`)
646 if out != fmt.Sprintf("hiSHtory: v0.Unknown\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) {
647 t.Fatalf("status command has unexpected output: %#v", out)
648 }
649
650 // Run a command many times
651 for i := 0; i < 25; i++ {
652 tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i))
653 }
654
655 // Check that it shows up correctly
656 out = hishtoryQuery(t, tester, `mycommand`)
657 if strings.Count(out, "\n") != 26 {
658 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
659 }
660 if strings.Count(out, "echo mycommand") != 24 {
661 t.Fatalf("hishtory query has the wrong number of commands=%d, out=%#v", strings.Count(out, "echo mycommand"), out)
662 }
663 require.Contains(t, out, "hishtory query mycommand")
664
665 // Run a few more commands including some empty lines that don't get recorded
666 tester.RunInteractiveShell(t, `echo mycommand-30
667
668
669echo mycommand-31
670echo mycommand-3`)
671
672 out = tester.RunInteractiveShell(t, "hishtory export | grep -v pipefail | grep -v '/tmp/client install'")
673 expectedOutput := "hishtory status\necho mycommand-0\necho mycommand-1\necho mycommand-2\necho mycommand-3\necho mycommand-4\necho mycommand-5\necho mycommand-6\necho mycommand-7\necho mycommand-8\necho mycommand-9\necho mycommand-10\necho mycommand-11\necho mycommand-12\necho mycommand-13\necho mycommand-14\necho mycommand-15\necho mycommand-16\necho mycommand-17\necho mycommand-18\necho mycommand-19\necho mycommand-20\necho mycommand-21\necho mycommand-22\necho mycommand-23\necho mycommand-24\nhishtory query mycommand\necho mycommand-30\necho mycommand-31\necho mycommand-3\n"
674 if diff := cmp.Diff(expectedOutput, out); diff != "" {
675 t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
676 }
677}
678
679func testRepeatedCommandAndQuery(t *testing.T, tester shellTester) {
680 // Set up

Callers 1

TestParamFunction · 0.85

Calls 4

BackupAndRestoreFunction · 0.92
installHishtoryFunction · 0.85
hishtoryQueryFunction · 0.85
RunInteractiveShellMethod · 0.65

Tested by

no test coverage detected