From d27825df5d235d6b5212464e88db6976a0ecbdf2 Mon Sep 17 00:00:00 2001 From: scnace Date: Thu, 23 Apr 2020 15:39:31 +0800 Subject: [PATCH] example: fix broken test --- example/model/model_test.go | 43 +++++++++++++------------------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/example/model/model_test.go b/example/model/model_test.go index 01eaa0f..df9abd9 100644 --- a/example/model/model_test.go +++ b/example/model/model_test.go @@ -159,8 +159,6 @@ var _ = Describe("redis-orm.mysql", func() { defer tx.Close() mgr := UserDBMgr(tx) - user.Name = "" - log.Println("user validator =>", user.Validate()) //! create n, err := mgr.Create(user) @@ -199,10 +197,6 @@ var _ = Describe("redis-orm.mysql", func() { Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) - n, err = mgr.Delete(user) - Ω(n).To(Equal(int64(1))) - Ω(err).ShouldNot(HaveOccurred()) - }) }) @@ -217,10 +211,10 @@ var _ = Describe("redis-orm.mysql", func() { Describe("CRUD", func() { It("user crud test", func() { user := UserMgr.NewUser() - user.Id = 2 - user.SubID = 20 - user.Name = "user01" - user.Mailbox = "user01@sss.fff" + user.Id = 3 + user.SubID = 2 + user.Name = "user02" + user.Mailbox = "user02@sss.fff" user.HeadUrl = "aaaa.png" user.Password = "123456" user.CreatedAt = time.Now() @@ -233,8 +227,6 @@ var _ = Describe("redis-orm.mysql", func() { defer tx.Close() mgr := UserDBMgr(tx) - user.Name = "" - log.Println("user validator =>", user.Validate()) //! create n, err := mgr.Create(user) @@ -248,8 +240,8 @@ var _ = Describe("redis-orm.mysql", func() { user.HeadUrl = "bbbb.png" user.UpdatedAt = time.Now() n, err = mgr.Update(user) - Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) + Ω(n).To(Equal(int64(1))) //! fetch check obj, err := mgr.Fetch(user.GetPrimaryKey()) @@ -273,18 +265,15 @@ var _ = Describe("redis-orm.mysql", func() { Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) - n, err = mgr.Delete(user) - Ω(n).To(Equal(int64(1))) - Ω(err).ShouldNot(HaveOccurred()) }) Measure("mysql.bench", func(b Benchmarker) { b.Time("crud.runtime", func() { user := UserMgr.NewUser() - user.Id = 3 - user.SubID = 30 - user.Name = "user01" - user.Mailbox = "user01@sss.fff" + user.Id = 5 + user.SubID = 3 + user.Name = "user03" + user.Mailbox = "user03@sss.fff" user.HeadUrl = "aaaa.png" user.Password = "123456" user.CreatedAt = time.Now() @@ -299,15 +288,15 @@ var _ = Describe("redis-orm.mysql", func() { //! create n, err := mgr.Create(user) - Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) + Ω(n).To(Equal(int64(1))) //! update user.HeadUrl = "bbbb.png" user.UpdatedAt = time.Now() n, err = mgr.Update(user) - Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) + Ω(n).To(Equal(int64(1))) //! fetch check obj, err := mgr.Fetch(user.GetPrimaryKey()) @@ -316,8 +305,8 @@ var _ = Describe("redis-orm.mysql", func() { //! delete n, err = mgr.Delete(user) - Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) + Ω(n).To(Equal(int64(1))) //! fetch check _, err = mgr.Fetch(user.GetPrimaryKey()) @@ -326,12 +315,9 @@ var _ = Describe("redis-orm.mysql", func() { //! save user.HeadUrl = "ccc.png" n, err = mgr.Save(user) - Ω(n).To(Equal(int64(1))) Ω(err).ShouldNot(HaveOccurred()) - - n, err = mgr.Delete(user) Ω(n).To(Equal(int64(1))) - Ω(err).ShouldNot(HaveOccurred()) + }) }, 1) }) @@ -575,8 +561,9 @@ var _ = Describe("redis-orm.redis", func() { Ω(err).ShouldNot(HaveOccurred()) Ω(obj.Name).To(Equal(fmt.Sprintf("name%d", 102))) - time.Sleep(time.Second) + time.Sleep(3 * time.Second) _, err = UserRedisMgr(Redis()).Fetch(userWithExpire.GetPrimaryKey()) + Ω(err).Should(HaveOccurred()) fmt.Printf("createWithExpire after expire:%v", err) Ω(strings.Contains(err.Error(), "not exist")).Should(Equal(true)) })