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

Function TestSortByConsistentTimezone

client/integration_test.go:2804–2842  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2802}
2803
2804func TestSortByConsistentTimezone(t *testing.T) {
2805 // Setup
2806 markTestForSharding(t, 7)
2807 tester := zshTester{}
2808 defer testutils.BackupAndRestore(t)()
2809 installHishtory(t, tester, "")
2810
2811 // Add an entry just to ensure we get consistent table sizing
2812 tester.RunInteractiveShell(t, "echo tablesizing")
2813
2814 // Add some entries with timestamps in different timezones
2815 db := hctx.GetDb(hctx.MakeContext())
2816 timestamp := int64(1650096186)
2817 la_time, err := time.LoadLocation("America/Los_Angeles")
2818 require.NoError(t, err)
2819 ny_time, err := time.LoadLocation("America/New_York")
2820 require.NoError(t, err)
2821 entry1 := testutils.MakeFakeHistoryEntry("first_entry")
2822 entry1.StartTime = time.Unix(timestamp, 0).In(ny_time)
2823 entry1.EndTime = time.Unix(timestamp+1, 0).In(ny_time)
2824 require.NoError(t, lib.ReliableDbCreate(db, entry1))
2825 entry2 := testutils.MakeFakeHistoryEntry("second_entry")
2826 entry2.StartTime = time.Unix(timestamp+1000, 0).In(la_time)
2827 entry2.EndTime = time.Unix(timestamp+1001, 0).In(la_time)
2828 require.NoError(t, lib.ReliableDbCreate(db, entry2))
2829 entry3 := testutils.MakeFakeHistoryEntry("third_entry")
2830 entry3.StartTime = time.Unix(timestamp+2000, 0).In(ny_time)
2831 entry3.EndTime = time.Unix(timestamp+2001, 0).In(ny_time)
2832 require.NoError(t, lib.ReliableDbCreate(db, entry3))
2833
2834 // And check that they're displayed in the correct order
2835 out := hishtoryQuery(t, tester, "-pipefail -tablesizing")
2836 testutils.CompareGoldens(t, out, "TestSortByConsistentTimezone-query")
2837 out = tester.RunInteractiveShell(t, `hishtory export -pipefail -tablesizing`)
2838 testutils.CompareGoldens(t, out, "TestSortByConsistentTimezone-export")
2839 out = captureTerminalOutput(t, tester, []string{"hishtory SPACE tquery ENTER", "-pipefail SPACE -tablesizing"})
2840 out = stripTuiCommandPrefix(t, out)
2841 require.Regexp(t, regexp.MustCompile(`Timestamp[\s\S]*Command[\s\S]*Apr 16 2022 01:36:26 PDT[\s\S]*third_entry[\s\S]*Apr 16 2022 01:19:46 PDT[\s\S]*second_entry[\s\S]*Apr 16 2022 01:03:06 PDT[\s\S]*first_entry`), out)
2842}
2843
2844func TestZDotDir(t *testing.T) {
2845 // Setup

Callers

nothing calls this directly

Calls 12

RunInteractiveShellMethod · 0.95
BackupAndRestoreFunction · 0.92
GetDbFunction · 0.92
MakeContextFunction · 0.92
MakeFakeHistoryEntryFunction · 0.92
ReliableDbCreateFunction · 0.92
CompareGoldensFunction · 0.92
markTestForShardingFunction · 0.85
installHishtoryFunction · 0.85
hishtoryQueryFunction · 0.85
captureTerminalOutputFunction · 0.85
stripTuiCommandPrefixFunction · 0.85

Tested by

no test coverage detected