From a9af51f5b2c21d3ae55322b1af9ad258e39d7d8e Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sat, 16 Apr 2022 00:56:08 -0700 Subject: [PATCH] Improved tests --- client/client_test.go | 30 +++++++++++++++++++++++++++--- client/lib/lib_test.go | 3 --- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 8861e73..0604244 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/exec" + "path" "regexp" "runtime" "strings" @@ -185,6 +186,19 @@ func testIntegration(t *testing.T) string { t.Fatalf("status command has unexpected output: %#v", out) } + // Assert that hishtory is correctly using the dev config.sh + homedir, err := os.UserHomeDir() + if err != nil { + t.Fatalf("failed to get homedir: %v", err) + } + dat, err := os.ReadFile(path.Join(homedir, shared.HISHTORY_PATH, "config.sh")) + if err != nil { + t.Fatalf("failed to read config.sh: %v", err) + } + if !strings.Contains(string(dat), "except it doesn't run the save process in the background") { + t.Fatalf("config.sh is the prod version when it shouldn't be, config.sh=%#v", dat) + } + // Test the banner os.Setenv("FORCED_BANNER", "HELLO_FROM_SERVER") out = hishtoryQuery(t, "") @@ -194,7 +208,7 @@ func testIntegration(t *testing.T) string { os.Setenv("FORCED_BANNER", "") // Test recording commands - out, err := RunInteractiveBashCommandsWithoutStrictMode(t, `set -m + out, err = RunInteractiveBashCommandsWithoutStrictMode(t, `set -m ls /a ls /bar ls /foo @@ -639,7 +653,17 @@ go build -o /tmp/client userSecret := matches[1] // Assert that config.sh isn't the dev version - // TODO: do ^ + homedir, err := os.UserHomeDir() + if err != nil { + t.Fatalf("failed to get homedir: %v", err) + } + dat, err := os.ReadFile(path.Join(homedir, shared.HISHTORY_PATH, "config.sh")) + if err != nil { + t.Fatalf("failed to read config.sh: %v", err) + } + if strings.Contains(string(dat), "except it doesn't run the save process in the background") { + t.Fatalf("config.sh is the testing version when it shouldn't be, config.sh=%#v", dat) + } // Test the status subcommand out = RunInteractiveBashCommands(t, `hishtory status`) @@ -648,7 +672,7 @@ go build -o /tmp/client } // Test recording commands - out, err := RunInteractiveBashCommandsWithoutStrictMode(t, `set -m + out, err = RunInteractiveBashCommandsWithoutStrictMode(t, `set -m ls /a echo foo`) if err != nil { diff --git a/client/lib/lib_test.go b/client/lib/lib_test.go index 1c88ae9..4b69030 100644 --- a/client/lib/lib_test.go +++ b/client/lib/lib_test.go @@ -61,9 +61,6 @@ func TestBuildHistoryEntry(t *testing.T) { if entry.StartTime.Unix() != 1641774958 { t.Fatalf("history entry has incorrect Unix time in the start time: %v", entry.StartTime.Unix()) } - - // Test the behavior when the command is prefixed with a space - // TODO: write a test for this } func TestGetUserSecret(t *testing.T) {