func TestPage(t *testing.T) { orm := getOrm() u := new(user) insert_count := toolkit.RandInt(5, 10) t.Log("insert records", insert_count) for i := 0; i < insert_count; i++ { u := new(user) u.Name = toolkit.RandomString(5) err := orm.Fork().Save(u) FatalError(t, err) } count, err := orm.Fork().Count(u) if count < 1 || err != nil { t.Fatal("can not test page because count error :", count, err) } page := 0 num := 5 total_page := count / num if count%num != 0 { total_page += 1 } for ; page < total_page; page++ { page_err, users := orm.Fork().Page(page, num).All(u) if page_err != nil { t.Fatal("page error:", page, num, page_err) } for _, tmp := range users { t.Log(tmp.(*user)) } t.Log(page, "end") } }
func TestEx(t *testing.T) { cache := getFileCache() category := "app/info" key := toolkit.RandomString(10) defer cache.Del(category, key) t1 := test_cache{} t1.Id = toolkit.RandInt(0, 10) t1.Name = toolkit.RandomString(10) err := cache.SetEx(category, key, t1) if err != nil { t.Fatal(err) } t2 := test_cache{} err, _ = cache.GetEx(category, key, &t2) if err != nil { t.Fatal(err) } if t1.Id != t2.Id || t2.Name != t2.Name { t.Fatal("error ex") } }