From 38b91f933cc79ca62f16554df5471e9e498b9688 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Mon, 18 Apr 2022 22:07:10 -0700 Subject: [PATCH] Add a timestamp test that I believe will fail for macos --- client/client_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/client/client_test.go b/client/client_test.go index 0f65bd8..f334d53 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -121,6 +121,7 @@ func TestParameterized(t *testing.T) { t.Run("testIntegrationWithNewDevice/"+tester.ShellName(), func(t *testing.T) { testIntegrationWithNewDevice(t, tester) }) t.Run("testHishtoryBackgroundSaving/"+tester.ShellName(), func(t *testing.T) { testHishtoryBackgroundSaving(t, tester) }) t.Run("testDisplayTable/"+tester.ShellName(), func(t *testing.T) { testDisplayTable(t, tester) }) + t.Run("testTimestampsAreReasonablyCorrect/"+tester.ShellName(), func(t *testing.T) { testTimestampsAreReasonablyCorrect(t, tester) }) } } @@ -750,6 +751,28 @@ func manuallySubmitHistoryEntry(t *testing.T, userSecret string, entry data.Hist } } +func testTimestampsAreReasonablyCorrect(t *testing.T, tester shellTester) { + // Setup + defer shared.BackupAndRestore(t)() + installHishtory(t, tester, "") + + // Record a command + out := tester.RunInteractiveShell(t, "echo hello") + if out != "hello\n" { + t.Fatalf("running echo hello had unexpected out=%#v", out) + } + + // Query for it and check that the timestamp that gets recorded looks reasonable + out = hishtoryQuery(t, tester, "echo hello") + if strings.Count(out, "\n") != 2 { + t.Fatalf("hishtory query has unexpected number of lines: out=%#v", out) + } + expectedDate := time.Now().Format("Jan 2 2006") + if !strings.Contains(out, expectedDate) { + t.Fatalf("hishtory query has an incorrect date: out=%#v", out) + } +} + func testHishtoryBackgroundSaving(t *testing.T, tester shellTester) { // Setup defer shared.BackupAndRestore(t)()