mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-14 09:08:44 +02:00
Untested: ctx wired through
This commit is contained in:
@ -8,8 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ddworken/hishtory/client/ctx"
|
||||
"github.com/ddworken/hishtory/client/data"
|
||||
"github.com/ddworken/hishtory/client/hctx"
|
||||
"github.com/ddworken/hishtory/shared"
|
||||
)
|
||||
|
||||
@ -21,7 +21,7 @@ func TestSetup(t *testing.T) {
|
||||
if _, err := os.Stat(path.Join(homedir, shared.HISHTORY_PATH, shared.CONFIG_PATH)); err == nil {
|
||||
t.Fatalf("hishtory secret file already exists!")
|
||||
}
|
||||
shared.Check(t, Setup([]string{}))
|
||||
shared.Check(t, Setup(hctx.MakeContext(), []string{}))
|
||||
if _, err := os.Stat(path.Join(homedir, shared.HISHTORY_PATH, shared.CONFIG_PATH)); err != nil {
|
||||
t.Fatalf("hishtory secret file does not exist after Setup()!")
|
||||
}
|
||||
@ -35,10 +35,10 @@ func TestSetup(t *testing.T) {
|
||||
func TestBuildHistoryEntry(t *testing.T) {
|
||||
defer shared.BackupAndRestore(t)()
|
||||
defer shared.RunTestServer()()
|
||||
shared.Check(t, Setup([]string{}))
|
||||
shared.Check(t, Setup(hctx.MakeContext(), []string{}))
|
||||
|
||||
// Test building an actual entry for bash
|
||||
entry, err := BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "bash", "120", " 123 ls /foo ", "1641774958"})
|
||||
entry, err := BuildHistoryEntry(hctx.MakeContext(), []string{"unused", "saveHistoryEntry", "bash", "120", " 123 ls /foo ", "1641774958"})
|
||||
shared.Check(t, err)
|
||||
if entry.ExitCode != 120 {
|
||||
t.Fatalf("history entry has unexpected exit code: %v", entry.ExitCode)
|
||||
@ -67,7 +67,7 @@ func TestBuildHistoryEntry(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test building an entry for zsh
|
||||
entry, err = BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "zsh", "120", "ls /foo\n", "1641774958"})
|
||||
entry, err = BuildHistoryEntry(hctx.MakeContext(), []string{"unused", "saveHistoryEntry", "zsh", "120", "ls /foo\n", "1641774958"})
|
||||
shared.Check(t, err)
|
||||
if entry.ExitCode != 120 {
|
||||
t.Fatalf("history entry has unexpected exit code: %v", entry.ExitCode)
|
||||
@ -92,29 +92,9 @@ func TestBuildHistoryEntry(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUserSecret(t *testing.T) {
|
||||
defer shared.BackupAndRestore(t)()
|
||||
defer shared.RunTestServer()()
|
||||
shared.Check(t, Setup([]string{}))
|
||||
secret1, err := GetUserSecret()
|
||||
shared.Check(t, err)
|
||||
if len(secret1) < 10 || strings.Contains(secret1, " ") || strings.Contains(secret1, "\n") {
|
||||
t.Fatalf("unexpected secret: %v", secret1)
|
||||
}
|
||||
|
||||
shared.Check(t, Setup([]string{}))
|
||||
secret2, err := GetUserSecret()
|
||||
shared.Check(t, err)
|
||||
|
||||
if secret1 == secret2 {
|
||||
t.Fatalf("GetUserSecret() returned the same values for different setups! val=%v", secret1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPersist(t *testing.T) {
|
||||
defer shared.BackupAndRestore(t)()
|
||||
db, err := ctx.OpenLocalSqliteDb()
|
||||
shared.Check(t, err)
|
||||
db := hctx.GetDb(hctx.MakeContext())
|
||||
|
||||
entry := data.MakeFakeHistoryEntry("ls ~/")
|
||||
db.Create(entry)
|
||||
@ -132,8 +112,7 @@ func TestPersist(t *testing.T) {
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
defer shared.BackupAndRestore(t)()
|
||||
db, err := ctx.OpenLocalSqliteDb()
|
||||
shared.Check(t, err)
|
||||
db := hctx.GetDb(hctx.MakeContext())
|
||||
|
||||
// Insert data
|
||||
entry1 := data.MakeFakeHistoryEntry("ls /foo")
|
||||
@ -158,8 +137,7 @@ func TestSearch(t *testing.T) {
|
||||
func TestAddToDbIfNew(t *testing.T) {
|
||||
// Set up
|
||||
defer shared.BackupAndRestore(t)()
|
||||
db, err := ctx.OpenLocalSqliteDb()
|
||||
shared.Check(t, err)
|
||||
db := hctx.GetDb(hctx.MakeContext())
|
||||
|
||||
// Add duplicate entries
|
||||
entry1 := data.MakeFakeHistoryEntry("ls /foo")
|
||||
|
Reference in New Issue
Block a user