You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.3 KiB

package main
import (
"os"
"testing"
"time"
bolt "go.etcd.io/bbolt"
)
func TestLoadEmptyMoments(t *testing.T) {
filename := "test.db"
db, err := bolt.Open(filename, 0666, nil)
if err != nil {
t.Fatalf("couldn't open db: %s: %s", filename, err)
}
defer func() {
os.Remove(filename)
}()
moments, err := loadMoments(db, "2018-01-01")
if err != nil {
t.Errorf("error while loading moments: %s", err)
}
if len(moments) != 0 {
t.Errorf("contains moments, which it should not")
}
}
func TestSaveMemoLoadMoments(t *testing.T) {
filename := "test.db"
db, err := bolt.Open(filename, 0666, nil)
if err != nil {
t.Fatalf("couldn't open db: %s: %s", filename, err)
}
defer func() {
os.Remove(filename)
}()
now := time.Now()
memo := "test"
err = saveMemo(db, now, memo)
if err != nil {
t.Errorf("error while saving a memo: %s", err)
}
prefix := now.Format("2006-01-02")
moments, err := loadMoments(db, prefix)
if err != nil {
t.Errorf("error while loading moments: %s", err)
}
if len(moments) != 1 {
t.Errorf("does not contain one moment which it should")
}
if moments[0].Time.Format(time.RFC3339) != now.Format(time.RFC3339) {
t.Errorf("%q != %q", moments[0].Time, now)
}
if moments[0].Memo != memo {
t.Errorf("%q != %q", moments[0].Memo, memo)
}
}