service_test.go 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package version
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/interface/main/creative/conf"
  6. "go-common/app/interface/main/creative/model/version"
  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. )
  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_VersionMap(t *testing.T) {
  31. var (
  32. c = context.Background()
  33. err error
  34. versions = make(map[string][]*version.Version)
  35. )
  36. Convey("versionMap", t, WithService(func(s *Service) {
  37. versions, err = s.versionMap(c)
  38. So(err, ShouldBeNil)
  39. So(versions, ShouldNotBeNil)
  40. }))
  41. }