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

Function testDisplayTable

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

Source from the content-addressed store, hash-verified

902}
903
904func testDisplayTable(t *testing.T, tester shellTester) {
905 // Setup
906 defer testutils.BackupAndRestore(t)()
907 userSecret := installHishtory(t, tester, "")
908
909 // Submit two fake entries
910 tmz, err := time.LoadLocation("America/Los_Angeles")
911 require.NoError(t, err)
912 entry1 := testutils.MakeFakeHistoryEntry("table_cmd1")
913 entry1.StartTime = time.Unix(1650096186, 0).In(tmz)
914 entry1.EndTime = time.Unix(1650096190, 0).In(tmz)
915 manuallySubmitHistoryEntry(t, userSecret, entry1)
916 entry2 := testutils.MakeFakeHistoryEntry("table_cmd2")
917 entry2.StartTime = time.Unix(1650096196, 0).In(tmz)
918 entry2.EndTime = time.Unix(1650096220, 0).In(tmz)
919 entry2.CurrentWorkingDirectory = "~/foo/"
920 entry2.ExitCode = 3
921 manuallySubmitHistoryEntry(t, userSecret, entry2)
922
923 // Query and check the table
924 tester.RunInteractiveShell(t, ` hishtory disable`)
925 out := hishtoryQuery(t, tester, "table")
926 testutils.CompareGoldens(t, out, "testDisplayTable-defaultColumns")
927
928 // Adjust the columns that should be displayed
929 tester.RunInteractiveShell(t, `hishtory config-set displayed-columns Hostname Command`)
930
931 // And check the table again
932 out = hishtoryQuery(t, tester, "table")
933 testutils.CompareGoldens(t, out, "testDisplayTable-customColumns")
934
935 // And again
936 tester.RunInteractiveShell(t, `hishtory config-set displayed-columns Hostname 'Exit Code' Command`)
937 out = hishtoryQuery(t, tester, "table")
938 testutils.CompareGoldens(t, out, "testDisplayTable-customColumns-2")
939
940 // And again
941 tester.RunInteractiveShell(t, `hishtory config-add displayed-columns CWD`)
942 out = hishtoryQuery(t, tester, "table")
943 testutils.CompareGoldens(t, out, "testDisplayTable-customColumns-3")
944
945 // Test displaying a command with multiple lines
946 entry3 := testutils.MakeFakeHistoryEntry("while :\ndo\nls /table/\ndone")
947 manuallySubmitHistoryEntry(t, userSecret, entry3)
948 out = hishtoryQuery(t, tester, "table")
949 testutils.CompareGoldens(t, out, "testDisplayTable-customColumns-multiLineCommand")
950
951 // Add a custom column
952 tester.RunInteractiveShell(t, `hishtory config-add custom-columns foo "echo aaaaaaaaaaaaa"`)
953 require.NoError(t, os.Chdir("/"))
954 tester.RunInteractiveShell(t, ` hishtory enable`)
955 tester.RunInteractiveShell(t, `echo table-1`)
956 tester.RunInteractiveShell(t, `echo table-2`)
957 tester.RunInteractiveShell(t, `echo bar`)
958 tester.RunInteractiveShell(t, ` hishtory disable`)
959 tester.RunInteractiveShell(t, `hishtory config-add displayed-columns foo`)
960
961 // And run a query and confirm it is displayed

Callers 1

TestParamFunction · 0.85

Calls 7

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

Tested by

no test coverage detected