service_test.go 873 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package template
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/interface/main/creative/conf"
  6. "go-common/app/interface/main/creative/model/template"
  7. "path/filepath"
  8. "testing"
  9. "time"
  10. . "github.com/smartystreets/goconvey/convey"
  11. "go-common/app/interface/main/creative/service"
  12. )
  13. var (
  14. s *Service
  15. )
  16. func init() {
  17. dir, _ := filepath.Abs("../../cmd/creative.toml")
  18. flag.Set("conf", dir)
  19. conf.Init()
  20. rpcdaos := service.NewRPCDaos(conf.Conf)
  21. s = New(conf.Conf, rpcdaos)
  22. time.Sleep(time.Second)
  23. }
  24. func WithService(f func(s *Service)) func() {
  25. return func() {
  26. Reset(func() {})
  27. f(s)
  28. }
  29. }
  30. func Test_Templates(t *testing.T) {
  31. var (
  32. mid int64 = 1
  33. c = context.TODO()
  34. err error
  35. res []*template.Template
  36. )
  37. Convey("Templates", t, WithService(func(s *Service) {
  38. res, err = s.Templates(c, mid)
  39. So(err, ShouldBeNil)
  40. So(res, ShouldNotBeNil)
  41. }))
  42. }