service_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/admin/main/credit/conf"
  9. "go-common/app/admin/main/credit/model/blocked"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. s *Service
  14. )
  15. // func CleanCache() {
  16. // //c := context.TODO()
  17. // //pool := redis.NewPool(conf.Conf.Redis.Config)
  18. // //pool.Get(c).Do("FLUSHDB")
  19. // }
  20. func init() {
  21. dir, _ := filepath.Abs("../cmd/convey-test.toml")
  22. flag.Set("conf", dir)
  23. conf.Init()
  24. s = New(conf.Conf)
  25. time.Sleep(time.Second)
  26. }
  27. // func WithService(f func(s *Service)) func() {
  28. // return func() {
  29. // Reset(func() { CleanCache() })
  30. // f(s)
  31. // }
  32. // }
  33. func TestService_loadConfig(t *testing.T) {
  34. s = New(conf.Conf)
  35. s.loadConfig()
  36. s.loadManager()
  37. //t.Logf("config (%+v)", s.c.Judge)
  38. }
  39. func Test_Infos(t *testing.T) {
  40. arg := &blocked.ArgBlockedSearch{}
  41. Convey("return someting", t, func() {
  42. list, pager, err := s.Infos(context.TODO(), arg)
  43. So(err, ShouldBeNil)
  44. So(list, ShouldNotBeNil)
  45. So(pager, ShouldNotBeNil)
  46. })
  47. }
  48. func Test_InfosEx(t *testing.T) {
  49. arg := &blocked.ArgBlockedSearch{}
  50. Convey("return someting", t, func() {
  51. list, err := s.InfosEx(context.TODO(), arg)
  52. So(err, ShouldBeNil)
  53. So(list, ShouldNotBeNil)
  54. })
  55. }
  56. func Test_Publishs(t *testing.T) {
  57. arg := &blocked.ArgPublishSearch{}
  58. Convey("return someting", t, func() {
  59. list, pager, err := s.Publishs(context.TODO(), arg)
  60. So(err, ShouldBeNil)
  61. So(list, ShouldNotBeNil)
  62. So(pager, ShouldNotBeNil)
  63. })
  64. }
  65. func Test_FormatCSV(t *testing.T) {
  66. var records [][]string
  67. record := []string{"sss", "ssss"}
  68. records = append(records, record)
  69. Convey("return someting", t, func() {
  70. buf := s.FormatCSV(records)
  71. So(buf, ShouldNotBeNil)
  72. })
  73. }
  74. func Test_Upload(t *testing.T) {
  75. Convey("return someting", t, func() {
  76. _, err := s.Upload(context.TODO(), "blocked_info", "", 12313, nil)
  77. So(err, ShouldBeNil)
  78. })
  79. }
  80. func Test_AddJury(t *testing.T) {
  81. arg := &blocked.ArgAddJurys{MIDs: []int64{111, 22}, OPID: 111, Day: 111, Send: 1}
  82. Convey("return someting", t, func() {
  83. err := s.AddJury(context.TODO(), arg)
  84. So(err, ShouldBeNil)
  85. })
  86. }
  87. func Test_Cases(t *testing.T) {
  88. arg := &blocked.ArgCaseSearch{}
  89. Convey("return someting", t, func() {
  90. list, pager, err := s.Cases(context.TODO(), arg)
  91. So(err, ShouldBeNil)
  92. So(list, ShouldNotBeNil)
  93. So(pager, ShouldNotBeNil)
  94. })
  95. }
  96. func Test_Opinions(t *testing.T) {
  97. arg := &blocked.ArgOpinionSearch{}
  98. Convey("return someting", t, func() {
  99. list, pager, err := s.Opinions(context.TODO(), arg)
  100. So(err, ShouldBeNil)
  101. So(list, ShouldNotBeNil)
  102. So(pager, ShouldNotBeNil)
  103. })
  104. }
  105. func Test_Jurys(t *testing.T) {
  106. arg := &blocked.ArgJurySearch{}
  107. Convey("return someting", t, func() {
  108. list, pager, err := s.Jurys(context.TODO(), arg)
  109. So(err, ShouldBeNil)
  110. So(list, ShouldNotBeNil)
  111. So(pager, ShouldNotBeNil)
  112. })
  113. }
  114. func Test_JurysEx(t *testing.T) {
  115. arg := &blocked.ArgJurySearch{}
  116. Convey("return someting", t, func() {
  117. res, err := s.JurysEx(context.TODO(), arg)
  118. So(err, ShouldBeNil)
  119. So(res, ShouldNotBeNil)
  120. })
  121. }
  122. func Test_KPIPoint(t *testing.T) {
  123. arg := &blocked.ArgKpiPointSearch{}
  124. Convey("return someting", t, func() {
  125. list, pager, err := s.KPIPoint(context.TODO(), arg)
  126. So(err, ShouldBeNil)
  127. So(list, ShouldNotBeNil)
  128. So(pager, ShouldNotBeNil)
  129. })
  130. }