refactoring, better tests, commit hash, banner, and tested working locally

This commit is contained in:
David Dworken
2022-04-06 22:43:07 -07:00
parent 684511f4f7
commit 1065fff062
11 changed files with 185 additions and 111 deletions

View File

@ -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)
}
}