res_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package resource
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/web-show/conf"
  9. rsmdl "go-common/app/interface/main/web-show/model/resource"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. const (
  13. _ip = "172.0.0.1"
  14. )
  15. var svf *Service
  16. func init() {
  17. dir, _ := filepath.Abs("../../cmd/web-show-test.toml")
  18. flag.Set("conf", dir)
  19. if err := conf.Init(); err != nil {
  20. panic(err)
  21. }
  22. if svf == nil {
  23. svf = New(conf.Conf)
  24. }
  25. time.Sleep(time.Second)
  26. }
  27. func WithService(f func(s *Service)) func() {
  28. return func() {
  29. f(svf)
  30. }
  31. }
  32. func TestService_Resource(t *testing.T) {
  33. Convey("should return without err", t, WithService(func(svf *Service) {
  34. arg := &rsmdl.ArgRes{
  35. Mid: 1,
  36. ID: 0,
  37. Pf: 0,
  38. Sid: "test",
  39. IP: _ip,
  40. Buvid: "test",
  41. }
  42. res, count, err := svf.Resource(context.TODO(), arg)
  43. So(err, ShouldBeNil)
  44. So(len(res), ShouldBeGreaterThan, 0)
  45. So(count, ShouldBeGreaterThan, 0)
  46. }))
  47. }
  48. func TestService_Resources(t *testing.T) {
  49. Convey("should return without err", t, WithService(func(svf *Service) {
  50. arg := &rsmdl.ArgRess{
  51. Mid: 1,
  52. Ids: []int64{1, 2, 3},
  53. Pf: 0,
  54. Sid: "test",
  55. IP: _ip,
  56. Buvid: "test",
  57. }
  58. res, count, err := svf.Resources(context.TODO(), arg)
  59. So(err, ShouldBeNil)
  60. So(len(res), ShouldBeGreaterThan, 0)
  61. So(count, ShouldBeGreaterThan, 0)
  62. }))
  63. }