service_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package medal
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/interface/main/creative/conf"
  6. mdMdl "go-common/app/interface/main/creative/model/medal"
  7. "path/filepath"
  8. "testing"
  9. "time"
  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_Medal(t *testing.T) {
  33. var (
  34. mid int64 = 1
  35. name = "name"
  36. c = context.TODO()
  37. err error
  38. res *mdMdl.Medal
  39. )
  40. Convey("Medal", t, WithService(func(s *Service) {
  41. res, err = s.Medal(c, mid)
  42. So(err, ShouldBeNil)
  43. So(res, ShouldNotBeNil)
  44. }))
  45. Convey("OpenMedal", t, WithService(func(s *Service) {
  46. err = s.OpenMedal(c, mid, name)
  47. So(err, ShouldBeNil)
  48. }))
  49. }