|
|
|
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 TestOtherDb(t *testing.T) {
|
|
|
|
var db stardb.StarDB
|
|
|
|
err := db.Open("sqlite", "./db.sqlite")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
r, err := NewRemind(&db, func(task Task) {
|
|
|
|
fmt.Println("hello world!", time.Now(), task.ID, task.Key, task.TmrInfo, task.Msg, task.Origin)
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Println(len(r.GetTasksByKey("705457681")))
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|