more tests + some todos where I could add even more

This commit is contained in:
David Dworken 2022-04-09 13:09:46 -07:00
parent 64935391b6
commit ac18b3d93e
3 changed files with 32 additions and 0 deletions

View File

@ -417,3 +417,5 @@ func TestGithubRedirects(t *testing.T) {
t.Fatalf("response is too short to be a binary, resp=%d", len(respBody))
}
}
// TODO: Maybe a dedicated unit test for retrieveAdditionalEntriesFromRemote

View File

@ -48,3 +48,5 @@ func TestParseTimeGenerously(t *testing.T) {
t.Fatalf("parsed time incorrectly: %d", ts.Unix())
}
}
// TODO: Maybe some dedicated unit tests for Search()

View File

@ -123,3 +123,31 @@ func TestSearch(t *testing.T) {
t.Fatalf("Search()[0]=%#v, expected: %#v", results[1], entry1)
}
}
func TestAddToDbIfNew(t *testing.T) {
// Set up
defer shared.BackupAndRestore(t)()
db, err := OpenLocalSqliteDb()
shared.Check(t, err)
// Add duplicate entries
entry1 := data.MakeFakeHistoryEntry("ls /foo")
AddToDbIfNew(db, entry1)
AddToDbIfNew(db, entry1)
entry2 := data.MakeFakeHistoryEntry("ls /foo")
AddToDbIfNew(db, entry2)
AddToDbIfNew(db, entry2)
AddToDbIfNew(db, entry1)
// Check there should only be two entries
var entries []data.HistoryEntry
result := db.Find(&entries)
if result.Error != nil {
t.Fatal(result.Error)
}
if len(entries) != 2 {
t.Fatalf("entries has an incorrect length: %d", len(entries))
}
}
// TODO: Some day find a way of testing the table display