service_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package academy
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/creative/conf"
  9. "go-common/app/interface/main/creative/model/academy"
  10. "go-common/app/interface/main/creative/service"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var (
  14. s *Service
  15. p *service.Public
  16. )
  17. func init() {
  18. dir, _ := filepath.Abs("../../cmd/creative.toml")
  19. flag.Set("conf", dir)
  20. conf.Init()
  21. rpcdaos := service.NewRPCDaos(conf.Conf)
  22. p = service.New(conf.Conf, rpcdaos)
  23. s = New(conf.Conf, rpcdaos, p)
  24. time.Sleep(time.Second)
  25. }
  26. func WithService(f func(s *Service)) func() {
  27. return func() {
  28. Reset(func() {})
  29. f(s)
  30. }
  31. }
  32. func Test_TagList(t *testing.T) {
  33. var (
  34. c = context.TODO()
  35. )
  36. Convey("TagList", t, WithService(func(s *Service) {
  37. res, err := s.TagList(c)
  38. So(err, ShouldBeNil)
  39. So(res, ShouldNotBeNil)
  40. }))
  41. }
  42. func Test_ArchivesWithES(t *testing.T) {
  43. var (
  44. c = context.TODO()
  45. aca = &academy.EsParam{
  46. Tid: []int64{},
  47. Business: 1,
  48. Pn: 1,
  49. Ps: 10,
  50. Keyword: "",
  51. Order: "",
  52. IP: "127.0.0.1",
  53. }
  54. )
  55. Convey("Archives", t, WithService(func(s *Service) {
  56. res, err := s.ArchivesWithES(c, aca)
  57. //spew.Dump(res, err)
  58. So(err, ShouldBeNil)
  59. So(res, ShouldNotBeNil)
  60. }))
  61. }
  62. func Test_AddFeedBack(t *testing.T) {
  63. var (
  64. c = context.TODO()
  65. category = "视频"
  66. course = "图像处理"
  67. suggest = "画质太差"
  68. mid = int64(123)
  69. )
  70. Convey("AddFeedBack", t, WithService(func(s *Service) {
  71. id, err := s.AddFeedBack(c, category, course, suggest, mid)
  72. So(err, ShouldBeNil)
  73. So(id, ShouldBeGreaterThan, 0)
  74. }))
  75. }
  76. func Test_RecommendV2(t *testing.T) {
  77. var (
  78. c = context.TODO()
  79. mid = int64(123)
  80. )
  81. Convey("RecommendV2", t, WithService(func(s *Service) {
  82. _, err := s.RecommendV2(c, mid)
  83. So(err, ShouldBeNil)
  84. }))
  85. }