sns_test.go 7.5 KB

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