user_base_test.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/bbq/user/api"
  5. "go-common/library/log"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaokeyUserBase(t *testing.T) {
  10. convey.Convey("keyUserBase", t, func(ctx convey.C) {
  11. var (
  12. mid = int64(88895104)
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. p1 := keyUserBase(mid)
  16. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestDaoTmpUserBase(t *testing.T) {
  23. convey.Convey("JustGetUserBase", t, func(ctx convey.C) {
  24. var (
  25. c = context.Background()
  26. mids = []int64{88895104}
  27. )
  28. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  29. res, err := d.UserBase(c, mids)
  30. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. ctx.So(res, convey.ShouldNotBeNil)
  33. })
  34. })
  35. })
  36. }
  37. func TestDaoRawUserBase(t *testing.T) {
  38. convey.Convey("RawUserBase", t, func(ctx convey.C) {
  39. var (
  40. c = context.Background()
  41. mids = []int64{88895104}
  42. )
  43. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  44. res, err := d.RawUserBase(c, mids)
  45. log.Infow(c, "log", "xxxxxxxxxxx", "res", res)
  46. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. ctx.So(res, convey.ShouldNotBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestDaoCacheUserBase(t *testing.T) {
  54. convey.Convey("CacheUserBase", t, func(ctx convey.C) {
  55. var (
  56. c = context.Background()
  57. mids = []int64{}
  58. )
  59. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  60. res, err := d.CacheUserBase(c, mids)
  61. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  62. ctx.So(err, convey.ShouldBeNil)
  63. ctx.So(res, convey.ShouldNotBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestDaoAddCacheUserBase(t *testing.T) {
  69. convey.Convey("AddCacheUserBase", t, func(ctx convey.C) {
  70. var (
  71. c = context.Background()
  72. userBases map[int64]*api.UserBase
  73. )
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. err := d.AddCacheUserBase(c, userBases)
  76. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. })
  81. }
  82. func TestDaoDelCacheUserBase(t *testing.T) {
  83. convey.Convey("DelCacheUserBase", t, func(ctx convey.C) {
  84. var (
  85. c = context.Background()
  86. mid = int64(0)
  87. )
  88. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  89. d.DelCacheUserBase(c, mid)
  90. ctx.Convey("No return values", func(ctx convey.C) {
  91. })
  92. })
  93. })
  94. }
  95. //
  96. //func TestDaoTxAddUserBase(t *testing.T) {
  97. // convey.Convey("TxAddUserBase", t, func(ctx convey.C) {
  98. // var (
  99. // c = context.Background()
  100. // tx = &sql.Tx{}
  101. // userBase = &api.UserBase{}
  102. // )
  103. // ctx.Convey("When everything goes positive", func(ctx convey.C) {
  104. // num, err := d.TxAddUserBase(c, tx, userBase)
  105. // ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  106. // ctx.So(err, convey.ShouldBeNil)
  107. // ctx.So(num, convey.ShouldNotBeNil)
  108. // })
  109. // })
  110. // })
  111. //}
  112. //
  113. //func TestDaoAddUserBaseUname(t *testing.T) {
  114. // convey.Convey("AddUserBaseUname", t, func(ctx convey.C) {
  115. // var (
  116. // c = context.Background()
  117. // mid = int64(88895104)
  118. // uname = "dfsfwe"
  119. // )
  120. // ctx.Convey("When everything goes positive", func(ctx convey.C) {
  121. // num, err := d.AddUserBaseUname(c, mid, uname)
  122. // ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  123. // ctx.So(err, convey.ShouldBeNil)
  124. // ctx.So(num, convey.ShouldNotBeNil)
  125. // })
  126. // })
  127. // })
  128. //}
  129. //
  130. //func TestDaoAddUserBase(t *testing.T) {
  131. // convey.Convey("AddUserBase", t, func(ctx convey.C) {
  132. // var (
  133. // c = context.Background()
  134. // userBase = &api.UserBase{}
  135. // )
  136. // ctx.Convey("When everything goes positive", func(ctx convey.C) {
  137. // num, err := d.AddUserBase(c, userBase)
  138. // ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  139. // ctx.So(err, convey.ShouldBeNil)
  140. // ctx.So(num, convey.ShouldNotBeNil)
  141. // })
  142. // })
  143. // })
  144. //}
  145. func TestDaoUpdateUserBaseUname(t *testing.T) {
  146. convey.Convey("UpdateUserBaseUname", t, func(ctx convey.C) {
  147. var (
  148. c = context.Background()
  149. mid = int64(0)
  150. uname = "sdfewxc"
  151. )
  152. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  153. num, err := d.UpdateUserBaseUname(c, mid, uname)
  154. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  155. ctx.So(err, convey.ShouldBeNil)
  156. ctx.So(num, convey.ShouldNotBeNil)
  157. })
  158. })
  159. })
  160. }
  161. func TestDaoUpdateUserBase(t *testing.T) {
  162. convey.Convey("UpdateUserBase", t, func(ctx convey.C) {
  163. var (
  164. c = context.Background()
  165. mid = int64(88895104)
  166. userBase = &api.UserBase{Uname: "sdfweo", Sex: 1, Face: "htttttt"}
  167. )
  168. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  169. num, err := d.UpdateUserBase(c, mid, userBase)
  170. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  171. ctx.So(err, convey.ShouldBeNil)
  172. ctx.So(num, convey.ShouldNotBeNil)
  173. })
  174. })
  175. })
  176. }
  177. func TestDaoUpdateUserField(t *testing.T) {
  178. convey.Convey("UpdateUserField", t, func(ctx convey.C) {
  179. var (
  180. c = context.Background()
  181. mid = int64(88895104)
  182. )
  183. tx, _ := d.BeginTran(c)
  184. defer func() {
  185. tx.Rollback()
  186. }()
  187. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  188. num, err := d.UpdateUserField(c, tx, mid, "uname", "unnnnnn")
  189. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  190. ctx.So(err, convey.ShouldBeNil)
  191. ctx.So(num, convey.ShouldNotBeNil)
  192. })
  193. })
  194. })
  195. convey.Convey("UpdateUserField", t, func(ctx convey.C) {
  196. var (
  197. c = context.Background()
  198. mid = int64(88895104)
  199. )
  200. tx, _ := d.BeginTran(c)
  201. defer func() {
  202. tx.Rollback()
  203. }()
  204. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  205. num, err := d.UpdateUserField(c, tx, mid, "face", "faaaaaa")
  206. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  207. ctx.So(err, convey.ShouldBeNil)
  208. ctx.So(num, convey.ShouldNotBeNil)
  209. })
  210. })
  211. })
  212. convey.Convey("UpdateUserField", t, func(ctx convey.C) {
  213. var (
  214. c = context.Background()
  215. mid = int64(88895104)
  216. )
  217. tx, _ := d.BeginTran(c)
  218. defer func() {
  219. tx.Rollback()
  220. }()
  221. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  222. num, err := d.UpdateUserField(c, tx, mid, "region", 11111)
  223. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  224. ctx.So(err, convey.ShouldBeNil)
  225. ctx.So(num, convey.ShouldNotBeNil)
  226. })
  227. })
  228. })
  229. convey.Convey("update cms_tag", t, func(ctx convey.C) {
  230. var (
  231. c = context.Background()
  232. mid = int64(88895104)
  233. )
  234. tx, _ := d.BeginTran(c)
  235. defer func() {
  236. //tx.Rollback()
  237. tx.Commit()
  238. }()
  239. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  240. num, err := d.UpdateUserField(c, tx, mid, "cms_tag", 1)
  241. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  242. ctx.So(err, convey.ShouldBeNil)
  243. ctx.So(num, convey.ShouldNotBeNil)
  244. })
  245. })
  246. })
  247. }
  248. func TestDaoCheckUname(t *testing.T) {
  249. convey.Convey("CheckUname", t, func(ctx convey.C) {
  250. var (
  251. c = context.Background()
  252. mid = int64(88895104)
  253. uname = "lkwejroiw"
  254. )
  255. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  256. err := d.CheckUname(c, mid, uname)
  257. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  258. ctx.So(err, convey.ShouldBeNil)
  259. })
  260. })
  261. })
  262. }