service_test.go 559 B

123456789101112131415161718192021222324252627282930313233343536
  1. package service
  2. import (
  3. "flag"
  4. "path/filepath"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/activity/conf"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var svr *Service
  11. func init() {
  12. dir, _ := filepath.Abs("../cmd/activity-admin-test.toml")
  13. flag.Set("conf", dir)
  14. conf.Init()
  15. svr = New(conf.Conf)
  16. time.Sleep(time.Second)
  17. }
  18. func WithService(f func(s *Service)) func() {
  19. return func() {
  20. Reset(func() {})
  21. f(svr)
  22. }
  23. }
  24. func Test_Service(t *testing.T) {
  25. Convey("service test", t, WithService(func(s *Service) {
  26. s.Wait()
  27. s.Close()
  28. }))
  29. }