mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-22 13:01:33 +02:00
Improved tests
This commit is contained in:
parent
c369661e53
commit
a9af51f5b2
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -185,6 +186,19 @@ func testIntegration(t *testing.T) string {
|
|||||||
t.Fatalf("status command has unexpected output: %#v", out)
|
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
|
// Test the banner
|
||||||
os.Setenv("FORCED_BANNER", "HELLO_FROM_SERVER")
|
os.Setenv("FORCED_BANNER", "HELLO_FROM_SERVER")
|
||||||
out = hishtoryQuery(t, "")
|
out = hishtoryQuery(t, "")
|
||||||
@ -194,7 +208,7 @@ func testIntegration(t *testing.T) string {
|
|||||||
os.Setenv("FORCED_BANNER", "")
|
os.Setenv("FORCED_BANNER", "")
|
||||||
|
|
||||||
// Test recording commands
|
// Test recording commands
|
||||||
out, err := RunInteractiveBashCommandsWithoutStrictMode(t, `set -m
|
out, err = RunInteractiveBashCommandsWithoutStrictMode(t, `set -m
|
||||||
ls /a
|
ls /a
|
||||||
ls /bar
|
ls /bar
|
||||||
ls /foo
|
ls /foo
|
||||||
@ -639,7 +653,17 @@ go build -o /tmp/client
|
|||||||
userSecret := matches[1]
|
userSecret := matches[1]
|
||||||
|
|
||||||
// Assert that config.sh isn't the dev version
|
// 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
|
// Test the status subcommand
|
||||||
out = RunInteractiveBashCommands(t, `hishtory status`)
|
out = RunInteractiveBashCommands(t, `hishtory status`)
|
||||||
@ -648,7 +672,7 @@ go build -o /tmp/client
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test recording commands
|
// Test recording commands
|
||||||
out, err := RunInteractiveBashCommandsWithoutStrictMode(t, `set -m
|
out, err = RunInteractiveBashCommandsWithoutStrictMode(t, `set -m
|
||||||
ls /a
|
ls /a
|
||||||
echo foo`)
|
echo foo`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,9 +61,6 @@ func TestBuildHistoryEntry(t *testing.T) {
|
|||||||
if entry.StartTime.Unix() != 1641774958 {
|
if entry.StartTime.Unix() != 1641774958 {
|
||||||
t.Fatalf("history entry has incorrect Unix time in the start time: %v", entry.StartTime.Unix())
|
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) {
|
func TestGetUserSecret(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user