sns_test.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "database/sql/driver"
  6. "reflect"
  7. "testing"
  8. "go-common/app/job/main/passport-sns/model"
  9. xsql "go-common/library/database/sql"
  10. "github.com/bouk/monkey"
  11. "github.com/smartystreets/goconvey/convey"
  12. )
  13. func TestDao_SnsUserByMid(t *testing.T) {
  14. convey.Convey("SnsUserByMid", t, func(ctx convey.C) {
  15. var (
  16. c = context.Background()
  17. mid = int64(0)
  18. platform = model.PlatformQQ
  19. )
  20. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  21. res, err := d.SnsUserByMid(c, mid, platform)
  22. ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldBeNil)
  24. ctx.So(res, convey.ShouldBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestDao_SnsUserByUnionID(t *testing.T) {
  30. convey.Convey("SnsUserByUnionID", t, func(ctx convey.C) {
  31. var (
  32. c = context.Background()
  33. unionID = ""
  34. platform = model.PlatformQQ
  35. )
  36. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  37. res, err := d.SnsUserByUnionID(c, unionID, platform)
  38. ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. ctx.So(res, convey.ShouldBeNil)
  41. })
  42. })
  43. })
  44. }
  45. func TestDao_AddSnsUser(t *testing.T) {
  46. convey.Convey("AddSnsUser", t, func(ctx convey.C) {
  47. var (
  48. c = context.Background()
  49. mid = int64(0)
  50. platform = model.PlatformQQ
  51. expires = int64(0)
  52. unionID = ""
  53. )
  54. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  55. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.snsDB), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
  56. return driver.RowsAffected(1), nil
  57. })
  58. defer mock.Unpatch()
  59. affected, err := d.AddSnsUser(c, mid, expires, unionID, platform)
  60. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. ctx.So(affected, convey.ShouldNotBeNil)
  63. })
  64. })
  65. })
  66. }
  67. func TestDao_UpdateSnsUser(t *testing.T) {
  68. convey.Convey("UpdateSnsUser", t, func(ctx convey.C) {
  69. var (
  70. c = context.Background()
  71. mid = int64(0)
  72. platform = model.PlatformQQ
  73. expires = int64(0)
  74. unionID = ""
  75. )
  76. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  77. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.snsDB), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
  78. return driver.RowsAffected(1), nil
  79. })
  80. defer mock.Unpatch()
  81. affected, err := d.UpdateSnsUser(c, mid, expires, unionID, platform)
  82. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. ctx.So(affected, convey.ShouldNotBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestDao_UpdateSnsToken(t *testing.T) {
  90. convey.Convey("UpdateSnsToken", t, func(ctx convey.C) {
  91. var (
  92. c = context.Background()
  93. a = &model.SnsToken{}
  94. )
  95. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  96. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.snsDB), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
  97. return driver.RowsAffected(1), nil
  98. })
  99. defer mock.Unpatch()
  100. affected, err := d.UpdateSnsToken(c, a)
  101. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  102. ctx.So(err, convey.ShouldBeNil)
  103. ctx.So(affected, convey.ShouldNotBeNil)
  104. })
  105. })
  106. })
  107. }
  108. func TestDao_TxAddSnsUser(t *testing.T) {
  109. convey.Convey("TxAddSnsUser", t, func(ctx convey.C) {
  110. var (
  111. tx, _ = d.BeginSnsTran(context.Background())
  112. a = &model.SnsUser{}
  113. )
  114. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  115. mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
  116. return driver.RowsAffected(1), nil
  117. })
  118. defer mock.Unpatch()
  119. affected, err := d.TxAddSnsUser(tx, a)
  120. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(affected, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestDao_TxAddSnsOpenID(t *testing.T) {
  128. convey.Convey("TxAddSnsOpenID", t, func(ctx convey.C) {
  129. var (
  130. tx, _ = d.BeginSnsTran(context.Background())
  131. a = &model.SnsOpenID{}
  132. )
  133. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  134. mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
  135. return driver.RowsAffected(1), nil
  136. })
  137. defer mock.Unpatch()
  138. affected, err := d.TxAddSnsOpenID(tx, a)
  139. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  140. ctx.So(err, convey.ShouldBeNil)
  141. ctx.So(affected, convey.ShouldNotBeNil)
  142. })
  143. })
  144. })
  145. }
  146. func TestDao_TxAddSnsToken(t *testing.T) {
  147. convey.Convey("TxAddSnsToken", t, func(ctx convey.C) {
  148. var (
  149. tx, _ = d.BeginSnsTran(context.Background())
  150. a = &model.SnsToken{}
  151. )
  152. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  153. mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
  154. return driver.RowsAffected(1), nil
  155. })
  156. defer mock.Unpatch()
  157. affected, err := d.TxAddSnsToken(tx, a)
  158. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  159. ctx.So(err, convey.ShouldBeNil)
  160. ctx.So(affected, convey.ShouldNotBeNil)
  161. })
  162. })
  163. })
  164. }
  165. func TestDao_DelSnsUser(t *testing.T) {
  166. convey.Convey("DelSnsUser", t, func(ctx convey.C) {
  167. var (
  168. c = context.Background()
  169. mid = int64(0)
  170. platform = model.PlatformQQ
  171. )
  172. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  173. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.snsDB), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
  174. return driver.RowsAffected(1), nil
  175. })
  176. defer mock.Unpatch()
  177. affected, err := d.DelSnsUser(c, mid, platform)
  178. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  179. ctx.So(err, convey.ShouldBeNil)
  180. ctx.So(affected, convey.ShouldNotBeNil)
  181. })
  182. })
  183. })
  184. }
  185. func TestDao_TxUpdateSnsUserExpires(t *testing.T) {
  186. convey.Convey("TxUpdateSnsUserExpires", t, func(ctx convey.C) {
  187. var (
  188. tx, _ = d.BeginSnsTran(context.Background())
  189. a = &model.SnsUser{}
  190. )
  191. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  192. mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
  193. return driver.RowsAffected(1), nil
  194. })
  195. defer mock.Unpatch()
  196. affected, err := d.TxUpdateSnsUserExpires(tx, a)
  197. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  198. ctx.So(err, convey.ShouldBeNil)
  199. ctx.So(affected, convey.ShouldNotBeNil)
  200. })
  201. })
  202. })
  203. }
  204. func TestDao_TxUpdateSnsUser(t *testing.T) {
  205. convey.Convey("TxUpdateSnsUser", t, func(ctx convey.C) {
  206. var (
  207. tx, _ = d.BeginSnsTran(context.Background())
  208. mid = int64(0)
  209. platform = model.PlatformQQ
  210. expires = int64(0)
  211. unionID = ""
  212. )
  213. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  214. mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
  215. return driver.RowsAffected(1), nil
  216. })
  217. defer mock.Unpatch()
  218. affected, err := d.TxUpdateSnsUser(tx, mid, expires, unionID, platform)
  219. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  220. ctx.So(err, convey.ShouldBeNil)
  221. ctx.So(affected, convey.ShouldNotBeNil)
  222. })
  223. })
  224. })
  225. }
  226. func TestDao_TxUpdateSnsToken(t *testing.T) {
  227. convey.Convey("TxUpdateSnsToken", t, func(ctx convey.C) {
  228. var (
  229. tx, _ = d.BeginSnsTran(context.Background())
  230. a = &model.SnsToken{}
  231. )
  232. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  233. mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
  234. return driver.RowsAffected(1), nil
  235. })
  236. defer mock.Unpatch()
  237. affected, err := d.TxUpdateSnsToken(tx, a)
  238. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  239. ctx.So(err, convey.ShouldBeNil)
  240. ctx.So(affected, convey.ShouldNotBeNil)
  241. })
  242. })
  243. })
  244. }
  245. func TestDao_openIDSuffix(t *testing.T) {
  246. convey.Convey("openIDSuffix", t, func(ctx convey.C) {
  247. res := openIDSuffix("")
  248. ctx.Convey("Then res should not be nil.", func(ctx convey.C) {
  249. ctx.So(res, convey.ShouldNotBeNil)
  250. })
  251. })
  252. }