From 267aa086fa2a212a485625033e0a30c1227ab4ef Mon Sep 17 00:00:00 2001 From: David Dworken Date: Thu, 27 Oct 2022 23:07:00 -0700 Subject: [PATCH] Add tests for configuring displayed-columns --- client/client_test.go | 32 +++++++++++++++++++++++++++----- hishtory.go | 10 ++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 6d0490a..4a4051d 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1598,25 +1598,47 @@ func testConfigGetSet(t *testing.T, tester shellTester) { defer testutils.BackupAndRestore(t)() installHishtory(t, tester, "") - // Initially is true + // Config-get and set for enable-control-r out := tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`) if out != "true" { t.Fatalf("unexpected config-get output: %#v", out) } - - // Set to false and check tester.RunInteractiveShell(t, `hishtory config-set enable-control-r false`) out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`) if out != "false" { t.Fatalf("unexpected config-get output: %#v", out) } - - // Set to true and check tester.RunInteractiveShell(t, `hishtory config-set enable-control-r true`) out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`) if out != "true" { t.Fatalf("unexpected config-get output: %#v", out) } + + // config for displayed-columns + out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`) + if out != "Hostname CWD Timestamp Runtime \"Exit Code\" Command \n" { + t.Fatalf("unexpected config-get output: %#v", out) + } + tester.RunInteractiveShell(t, `hishtory config-set displayed-columns Hostname Command 'Exit Code'`) + out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`) + if out != "Hostname Command \"Exit Code\" \n" { + t.Fatalf("unexpected config-get output: %#v", out) + } + tester.RunInteractiveShell(t, `hishtory config-add displayed-columns Timestamp`) + out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`) + if out != "Hostname Command \"Exit Code\" Timestamp \n" { + t.Fatalf("unexpected config-get output: %#v", out) + } + tester.RunInteractiveShell(t, `hishtory config-delete displayed-columns Hostname`) + out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`) + if out != "Command \"Exit Code\" Timestamp \n" { + t.Fatalf("unexpected config-get output: %#v", out) + } + tester.RunInteractiveShell(t, `hishtory config-add displayed-columns foobar`) + out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`) + if out != "Command \"Exit Code\" Timestamp foobar \n" { + t.Fatalf("unexpected config-get output: %#v", out) + } } func clearControlRSearchFromConfig(t *testing.T) { diff --git a/hishtory.go b/hishtory.go index 478a679..b1f4144 100644 --- a/hishtory.go +++ b/hishtory.go @@ -126,8 +126,14 @@ func main() { case "enable-control-r": fmt.Printf("%v", config.ControlRSearchEnabled) case "displayed-columns": - // TODO: better formatting for the below - fmt.Printf("%#v", config.DisplayedColumns) + for _, col := range config.DisplayedColumns { + if strings.Contains(col, " ") { + fmt.Printf("%q ", col) + } else { + fmt.Print(col + " ") + } + } + fmt.Print("\n") case "custom-columns": // TODO: better formatting for this fmt.Printf("%#v", config.CustomColumns)