mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-23 00:34:27 +01:00
27 lines
660 B
Go
27 lines
660 B
Go
package shared
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestPersist(t *testing.T) {
|
|
defer BackupAndRestore(t)
|
|
Check(t, Setup([]string{}))
|
|
entry, err := BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls / "})
|
|
Check(t, err)
|
|
Check(t, Persist(*entry))
|
|
|
|
db, err := OpenDB()
|
|
Check(t, err)
|
|
var historyEntries []*HistoryEntry
|
|
result := db.Find(&historyEntries)
|
|
Check(t, result.Error)
|
|
if len(historyEntries) != 1 {
|
|
t.Fatalf("DB has %d entries, expected 1!", len(historyEntries))
|
|
}
|
|
dbEntry := historyEntries[0]
|
|
if !EntryEquals(*entry, *dbEntry) {
|
|
t.Fatalf("DB data is different than input! \ndb =%#v \ninput=%#v", *dbEntry, *entry)
|
|
}
|
|
}
|