mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Add tests for errors in testTui
This commit is contained in:
parent
df4dff6706
commit
fcf05ac21a
@ -104,6 +104,7 @@ func TestParam(t *testing.T) {
|
||||
t.Run("testTui/resize", testTui_resize)
|
||||
t.Run("testTui/delete", testTui_delete)
|
||||
t.Run("testTui/color", testTui_color)
|
||||
t.Run("testTui/errors", testTui_errors)
|
||||
|
||||
// Assert there are no leaked connections
|
||||
assertNoLeakedConnections(t)
|
||||
@ -1609,8 +1610,6 @@ func TestFish(t *testing.T) {
|
||||
testutils.CompareGoldens(t, out, "TestFish-table")
|
||||
}
|
||||
|
||||
// TODO(ddworken): Run TestTui in online and offline mode
|
||||
|
||||
func setupTestTui(t testing.TB, onlineStatus OnlineStatus) (shellTester, string, *gorm.DB) {
|
||||
tester := zshTester{}
|
||||
userSecret := installWithOnlineStatus(t, tester, onlineStatus)
|
||||
@ -1906,6 +1905,32 @@ func testTui_general(t *testing.T, onlineStatus OnlineStatus) {
|
||||
assertNoLeakedConnections(t)
|
||||
}
|
||||
|
||||
func testTui_errors(t *testing.T) {
|
||||
// Setup
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester, _, _ := setupTestTui(t, Online)
|
||||
|
||||
// Check the output when the device is offline
|
||||
os.Setenv("HISHTORY_SIMULATE_NETWORK_ERROR", "1")
|
||||
out := captureTerminalOutput(t, tester, []string{"hishtory SPACE tquery ENTER"})
|
||||
os.Setenv("HISHTORY_SIMULATE_NETWORK_ERROR", "")
|
||||
if len(strings.Split(out, "hishtory tquery")) != 2 {
|
||||
t.Fatalf("failed to split out=%#v", out)
|
||||
}
|
||||
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
||||
testutils.CompareGoldens(t, out, "TestTui-Offline")
|
||||
|
||||
// Check the output when the device is offline AND there is an invalid search
|
||||
os.Setenv("HISHTORY_SIMULATE_NETWORK_ERROR", "1")
|
||||
out = captureTerminalOutput(t, tester, []string{"hishtory SPACE tquery ENTER", "ls:"})
|
||||
os.Setenv("HISHTORY_SIMULATE_NETWORK_ERROR", "")
|
||||
if len(strings.Split(out, "hishtory tquery")) != 2 {
|
||||
t.Fatalf("failed to split out=%#v", out)
|
||||
}
|
||||
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
||||
testutils.CompareGoldens(t, out, "TestTui-OfflineInvalid")
|
||||
}
|
||||
|
||||
func testControlR(t *testing.T, tester shellTester, shellName string, onlineStatus OnlineStatus) {
|
||||
// Setup
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
|
29
client/lib/goldens/TestTui-Offline
Normal file
29
client/lib/goldens/TestTui-Offline
Normal file
@ -0,0 +1,29 @@
|
||||
Warning: failed to contact the hishtory backend (are you offline?), so some results may be stale
|
||||
|
||||
Search Query: > ls
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:21 PDT 3s 2 echo 'aaaaaa bbbb' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
hiSHtory: Search your shell history • ctrl+h help
|
30
client/lib/goldens/TestTui-OfflineInvalid
Normal file
30
client/lib/goldens/TestTui-OfflineInvalid
Normal file
@ -0,0 +1,30 @@
|
||||
Warning: failed to contact the hishtory backend (are you offline?), so some results may be stale
|
||||
Warning: failed to search: search query contains unknown search atom 'ls' that doesn't match any column names
|
||||
|
||||
Search Query: > ls:
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
hiSHtory: Search your shell history • ctrl+h help
|
Loading…
Reference in New Issue
Block a user