mc_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/passport-sns/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDao_snsKey(t *testing.T) {
  9. convey.Convey("snsKey", t, func(ctx convey.C) {
  10. var (
  11. platform = model.PlatformQQStr
  12. mid = int64(0)
  13. )
  14. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  15. res := snsKey(platform, mid)
  16. ctx.Convey("Then res should not be nil.", func(ctx convey.C) {
  17. ctx.So(res, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestDao_oauth2Key(t *testing.T) {
  23. convey.Convey("oauth2Key", t, func(ctx convey.C) {
  24. var (
  25. platform = model.PlatformQQStr
  26. openID = ""
  27. )
  28. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  29. res := oauth2Key(platform, openID)
  30. ctx.Convey("Then res should not be nil.", func(ctx convey.C) {
  31. ctx.So(res, convey.ShouldNotBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestDao_SetSnsCache(t *testing.T) {
  37. convey.Convey("SetSnsCache", t, func(ctx convey.C) {
  38. var (
  39. c = context.Background()
  40. mid = int64(0)
  41. platform = model.PlatformQQStr
  42. qq = &model.SnsProto{}
  43. )
  44. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  45. err := d.SetSnsCache(c, mid, platform, qq)
  46. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. })
  49. })
  50. })
  51. }
  52. func TestDao_SetOauth2Cache(t *testing.T) {
  53. convey.Convey("SetOauth2Cache", t, func(ctx convey.C) {
  54. var (
  55. c = context.Background()
  56. openID = ""
  57. platform = model.PlatformQQStr
  58. qq = &model.Oauth2Proto{}
  59. )
  60. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  61. err := d.SetOauth2Cache(c, openID, platform, qq)
  62. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestDao_SnsCache(t *testing.T) {
  69. convey.Convey("SnsCache", t, func(ctx convey.C) {
  70. var (
  71. c = context.Background()
  72. platform = model.PlatformQQStr
  73. mid = int64(0)
  74. midNotExist = int64(-1)
  75. )
  76. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  77. info, err := d.SnsCache(c, mid, platform)
  78. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. ctx.So(info, convey.ShouldNotBeNil)
  81. })
  82. info2, err2 := d.SnsCache(c, midNotExist, platform)
  83. ctx.Convey("Then err should be nil.info should be nil.", func(ctx convey.C) {
  84. ctx.So(err2, convey.ShouldBeNil)
  85. ctx.So(info2, convey.ShouldBeNil)
  86. })
  87. })
  88. })
  89. }
  90. func TestDao_Oauth2Cache(t *testing.T) {
  91. convey.Convey("Oauth2Cache", t, func(ctx convey.C) {
  92. var (
  93. c = context.Background()
  94. openID = ""
  95. openIDNotExist = "-1"
  96. platform = model.PlatformQQStr
  97. )
  98. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  99. info, err := d.Oauth2Cache(c, openID, platform)
  100. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  101. ctx.So(err, convey.ShouldBeNil)
  102. ctx.So(info, convey.ShouldNotBeNil)
  103. })
  104. info2, err2 := d.Oauth2Cache(c, openIDNotExist, platform)
  105. ctx.Convey("Then err should be nil.info should be nil.", func(ctx convey.C) {
  106. ctx.So(err2, convey.ShouldBeNil)
  107. ctx.So(info2, convey.ShouldBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestDao_DelSnsCache(t *testing.T) {
  113. convey.Convey("DelSnsCache", t, func(ctx convey.C) {
  114. var (
  115. c = context.Background()
  116. mid = int64(0)
  117. platform = model.PlatformQQStr
  118. )
  119. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  120. err := d.DelSnsCache(c, mid, platform)
  121. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestDao_DelOauth2Cache(t *testing.T) {
  128. convey.Convey("DelOauth2Cache", t, func(ctx convey.C) {
  129. var (
  130. c = context.Background()
  131. openID = ""
  132. platform = model.PlatformQQStr
  133. )
  134. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  135. err := d.DelOauth2Cache(c, openID, platform)
  136. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. })
  139. })
  140. })
  141. }