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

59 lines
1.0 KiB
Go

package remind
import (
"b612.me/stardb"
"fmt"
_ "github.com/glebarez/go-sqlite"
"os"
"testing"
"time"
)
func exists(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}
return err == nil
}
func TestRemind(t *testing.T) {
var db stardb.StarDB
err := db.Open("sqlite", "./remind.db")
if err != nil {
t.Fatal(err)
}
sign := make(chan int)
r, err := NewRemind(&db, func(task Task) {
fmt.Println("hello world!", time.Now(), task.ID, task.Key, task.TmrInfo, task.Msg, task.Origin)
sign <- 1
})
if err != nil {
t.Fatal(err)
}
fmt.Println("length of remind", len(r.ListTasks()))
if len(r.ListTasks()) < 2 {
tk, err := r.AddTask("每8秒提醒我吃饭", "干饭", []byte{1, 2, 3})
if err != nil {
t.Fatal(err)
}
tmr := tk.GetTimer()
fmt.Println(tmr.NextTimer())
}
i := 0
for {
select {
case <-sign:
i++
break
case <-time.After(time.Second * 15):
t.FailNow()
}
time.Sleep(time.Second)
fmt.Println(len(r.ListTasks()))
if i == 3 {
break
}
}
}