diff --git a/client/client_test.go b/client/client_test.go index ca5b750..17348e0 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/exec" + "os/user" "path" "regexp" "runtime" @@ -24,6 +25,7 @@ import ( "github.com/ddworken/hishtory/client/lib" "github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared/testutils" + "github.com/stretchr/testify/require" ) func skipSlowTests() bool { @@ -92,9 +94,7 @@ type zshTester struct { func (z zshTester) RunInteractiveShell(t *testing.T, script string) string { res, err := z.RunInteractiveShellRelaxed(t, "set -eo pipefail\n"+script) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return res } @@ -374,9 +374,7 @@ echo thisisnotrecorded sleep 0.5 hishtory enable echo thisisrecorded`) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if out != "foo\nbar\nthisisnotrecorded\nthisisrecorded\n" { t.Fatalf("unexpected output from running commands: %#v", out) } @@ -472,9 +470,7 @@ notacommand cd /tmp/ echo querybydir hishtory disable`) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // A super basic query just to ensure the basics are working out := hishtoryQuery(t, tester, `echo`) @@ -1017,9 +1013,7 @@ CGO_ENABLED=0 go build -o /tmp/client // Test recording commands out, err = tester.RunInteractiveShellRelaxed(t, `ls /a echo foo`) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if out != "foo\n" { t.Fatalf("unexpected output from running commands: %#v", out) } @@ -1257,9 +1251,7 @@ func testInstallViaPythonScriptChild(t *testing.T, tester shellTester) { // Test the status subcommand downloadData, err := lib.GetDownloadData() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) out = tester.RunInteractiveShell(t, `hishtory status`) expectedOut := fmt.Sprintf("hiSHtory: %s\nEnabled: true\nSecret Key: %s\nCommit Hash: ", downloadData.Version, userSecret) if !strings.Contains(out, expectedOut) { @@ -1293,9 +1285,7 @@ hishtory enable echo thisisrecorded echo bar & sleep 1`) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if out != "foo\nbar\nthisisnotrecorded\nthisisrecorded\nbar\n" { t.Fatalf("unexpected output from running commands: %#v", out) } @@ -1364,19 +1354,13 @@ func TestStripBashTimePrefix(t *testing.T) { // Add a HISTTIMEFORMAT to the bashrc homedir, err := os.UserHomeDir() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) f, err := os.OpenFile(path.Join(homedir, data.GetHishtoryPath(), "config.sh"), os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer f.Close() _, err = f.WriteString("\nexport HISTTIMEFORMAT='%F %T '\n") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // Record a command tester.RunInteractiveShell(t, `ls -Slah`) @@ -1389,19 +1373,13 @@ func TestStripBashTimePrefix(t *testing.T) { // Update it to another complex one homedir, err = os.UserHomeDir() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) f, err = os.OpenFile(path.Join(homedir, data.GetHishtoryPath(), "config.sh"), os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer f.Close() _, err = f.WriteString("\nexport HISTTIMEFORMAT='[%c] '\n") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // Record a command tester.RunInteractiveShell(t, `echo foo`) @@ -1967,6 +1945,17 @@ func TestTui(t *testing.T) { out = strings.Split(strings.TrimSpace(strings.Split(out, "hishtory tquery")[1]), "\n")[0] testutils.CompareGoldens(t, out, "TestTui-SelectAndCd") + // Test the User column + tester.RunInteractiveShell(t, `hishtory config-add displayed-columns User`) + out = captureTerminalOutput(t, tester, []string{ + "hishtory SPACE tquery ENTER", + }) + out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1]) + require.Contains(t, out, " User") + u, err := user.Current() + require.NoError(t, err) + require.Contains(t, out, " "+u.Username+" ") + // Assert there are no leaked connections assertNoLeakedConnections(t) }