mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 23:17:55 +02:00
refactoring, better tests, commit hash, banner, and tested working locally
This commit is contained in:
@ -70,3 +70,48 @@ func TestGetUserSecret(t *testing.T) {
|
||||
t.Fatalf("GetUserSecret() returned the same values for different setups! val=%v", secret1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestPersist(t *testing.T) {
|
||||
defer shared.BackupAndRestore(t)()
|
||||
db, err := OpenLocalSqliteDb()
|
||||
shared.Check(t, err)
|
||||
|
||||
entry := shared.MakeFakeHistoryEntry("ls ~/")
|
||||
db.Create(entry)
|
||||
var historyEntries []*shared.HistoryEntry
|
||||
result := db.Find(&historyEntries)
|
||||
shared.Check(t, result.Error)
|
||||
if len(historyEntries) != 1 {
|
||||
t.Fatalf("DB has %d entries, expected 1!", len(historyEntries))
|
||||
}
|
||||
dbEntry := historyEntries[0]
|
||||
if !shared.EntryEquals(entry, *dbEntry) {
|
||||
t.Fatalf("DB data is different than input! \ndb =%#v \ninput=%#v", *dbEntry, entry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
defer shared.BackupAndRestore(t)()
|
||||
db, err := OpenLocalSqliteDb()
|
||||
shared.Check(t, err)
|
||||
|
||||
// Insert data
|
||||
entry1 := shared.MakeFakeHistoryEntry("ls /foo")
|
||||
db.Create(entry1)
|
||||
entry2 := shared.MakeFakeHistoryEntry("ls /bar")
|
||||
db.Create(entry2)
|
||||
|
||||
// Search for data
|
||||
results, err := shared.Search(db, "ls", 5)
|
||||
shared.Check(t, err)
|
||||
if len(results) != 2 {
|
||||
t.Fatalf("Search() returned %d results, expected 2!", len(results))
|
||||
}
|
||||
if !shared.EntryEquals(*results[0], entry2) {
|
||||
t.Fatalf("Search()[0]=%#v, expected: %#v", results[0], entry2)
|
||||
}
|
||||
if !shared.EntryEquals(*results[1], entry1) {
|
||||
t.Fatalf("Search()[0]=%#v, expected: %#v", results[1], entry1)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user