cache_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "flag"
  6. "fmt"
  7. "testing"
  8. "time"
  9. "go-common/app/service/openplatform/anti-fraud/conf"
  10. "go-common/app/service/openplatform/anti-fraud/model"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. const _key = "AntiFraud:BANKID_1527233672941"
  14. var qustion = &model.ArgGetQuestion{UID: "1111", TargetItem: "1111", TargetItemType: 1, Source: 1, Platform: 1, ComponentID: 123}
  15. func init() {
  16. flag.Parse()
  17. if err := conf.Init(); err != nil {
  18. panic(fmt.Errorf("conf.Init() error(%v)", err))
  19. }
  20. d = New(conf.Conf)
  21. }
  22. func TestSetex(t *testing.T) {
  23. Convey("TestSetex", t, func() {
  24. err := d.Setex(context.TODO(), "BANK_1527061216377_QUESTIONS", 1, time.Hour)
  25. So(err, ShouldBeNil)
  26. })
  27. }
  28. func TestSetObj(t *testing.T) {
  29. Convey("TestSetex", t, func() {
  30. obj := &model.QuestionBank{}
  31. reply := []byte(`{"qb_id":1527233672941,"qb_name":"wlt","cd_time":0,"max_retry_time":22,"is_deleted":0}`)
  32. err := json.Unmarshal(reply, obj)
  33. if err != nil {
  34. return
  35. }
  36. d.GetObj(context.TODO(), _key, obj)
  37. data, err := d.GetQusBankInfoCache(context.TODO(), 1527233672941)
  38. So(err, ShouldBeNil)
  39. So(data, ShouldNotBeNil)
  40. })
  41. }
  42. //
  43. func TestGetObj(t *testing.T) {
  44. Convey("TestSetex", t, func() {
  45. data := &model.QuestionBank{}
  46. err := d.GetObj(context.TODO(), _key, data)
  47. So(err, ShouldBeNil)
  48. })
  49. }
  50. func TestGetPic(t *testing.T) {
  51. Convey("TestGetPic", t, func() {
  52. oi, _ := d.GetPic(context.TODO(), 4)
  53. So(oi, ShouldNotBeNil)
  54. })
  55. }
  56. func TestPushAllPic(t *testing.T) {
  57. Convey("TestGetPic", t, func() {
  58. data := &model.ArgGetQuestion{
  59. UID: "111111",
  60. TargetItem: "1111",
  61. TargetItemType: 1,
  62. Source: 1,
  63. Platform: 1,
  64. ComponentID: 123,
  65. }
  66. _, err := d.GetRandPic(context.TODO(), data)
  67. So(err, ShouldBeNil)
  68. })
  69. }
  70. func TestGetCacheQus(t *testing.T) {
  71. Convey("TestGetCacheQus", t, func() {
  72. _, err := d.GetCacheQus(context.TODO(), 1527241107344)
  73. So(err, ShouldBeNil)
  74. })
  75. }
  76. func TestGetQusKey(t *testing.T) {
  77. Convey("TestGetQusKey", t, func() {
  78. oi := d.GetQusKey(_keyAnsweredIds, qustion)
  79. So(oi, ShouldNotBeNil)
  80. })
  81. }
  82. func TestQusFetchTime(t *testing.T) {
  83. Convey("TestQusFetchTime", t, func() {
  84. oi := d.QusFetchTime(context.TODO(), qustion)
  85. So(oi, ShouldNotBeNil)
  86. })
  87. }
  88. func TestSetComponentId(t *testing.T) {
  89. Convey("TestSetComponentId", t, func() {
  90. err := d.SetComponentID(context.TODO(), qustion)
  91. So(err, ShouldBeNil)
  92. })
  93. }
  94. func TestGetComponentId(t *testing.T) {
  95. Convey("TestGetComponentId", t, func() {
  96. oi, err := d.GetComponentID(context.TODO(), qustion)
  97. So(oi, ShouldNotBeNil)
  98. So(err, ShouldBeNil)
  99. })
  100. }
  101. func TestIncrComponentTimes(t *testing.T) {
  102. Convey("TestIncrComponentTimes", t, func() {
  103. err := d.IncrComponentTimes(context.TODO(), qustion)
  104. So(err, ShouldBeNil)
  105. })
  106. }
  107. func TestGetRandPic(t *testing.T) {
  108. Convey("TestGetRandPic", t, func() {
  109. oi, err := d.GetRandPic(context.TODO(), qustion)
  110. So(err, ShouldBeNil)
  111. So(oi, ShouldNotBeNil)
  112. })
  113. }
  114. func TestSetAnsweredID(t *testing.T) {
  115. Convey("TestSetAnsweredID", t, func() {
  116. _, err := d.RedisDo(context.TODO(), "SADD", "wlt", 1222)
  117. So(err, ShouldBeNil)
  118. })
  119. }