mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-23 05:51:08 +01:00
Add a test for displaying a table
This commit is contained in:
parent
a9af51f5b2
commit
62a83b76b1
@ -702,3 +702,28 @@ echo foo`)
|
||||
t.Fatalf("output contains unexpected item, out=%#v", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisplayTable(t *testing.T) {
|
||||
// Setup
|
||||
defer shared.BackupAndRestore(t)()
|
||||
userSecret := installHishtory(t, "")
|
||||
|
||||
// Submit two fake entries
|
||||
entry1 := data.MakeFakeHistoryEntry("table_cmd1")
|
||||
entry1.StartTime = time.Unix(1650096186, 0)
|
||||
entry1.EndTime = time.Unix(1650096190, 0)
|
||||
manuallySubmitHistoryEntry(t, userSecret, entry1)
|
||||
entry2 := data.MakeFakeHistoryEntry("table_cmd2")
|
||||
entry2.StartTime = time.Unix(1650096196, 0)
|
||||
entry2.EndTime = time.Unix(1650096220, 0)
|
||||
entry2.CurrentWorkingDirectory = "~/foo/"
|
||||
entry2.ExitCode = 3
|
||||
manuallySubmitHistoryEntry(t, userSecret, entry2)
|
||||
|
||||
// Query and check the table
|
||||
out := RunInteractiveBashCommands(t, "hishtory query table")
|
||||
expectedOutput := "Hostname CWD Timestamp Runtime Exit Code Command \nlocalhost ~/foo/ Apr 16 2022 01:03:16 -0700 24s 3 table_cmd2 \nlocalhost /tmp/ Apr 16 2022 01:03:06 -0700 4s 2 table_cmd1 \n"
|
||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||
t.Fatalf("hishtory query table test mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||
}
|
||||
}
|
||||
|
@ -151,5 +151,3 @@ func TestAddToDbIfNew(t *testing.T) {
|
||||
t.Fatalf("entries has an incorrect length: %d", len(entries))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Some day find a way of testing the table display
|
||||
|
Loading…
Reference in New Issue
Block a user