service_test.go 586 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package service
  2. import (
  3. "flag"
  4. "os"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/reply/conf"
  8. "go-common/library/log"
  9. _ "github.com/go-sql-driver/mysql"
  10. )
  11. var svr *Service
  12. func TestMain(m *testing.M) {
  13. flag.Parse()
  14. conf.ConfPath = "../cmd/reply-admin-test.toml"
  15. if err := conf.Init(); err != nil {
  16. panic(err)
  17. }
  18. log.Init(conf.Conf.Log)
  19. defer log.Close()
  20. svr = New(conf.Conf)
  21. time.Sleep(time.Millisecond * 300)
  22. m.Run()
  23. //flush db and log
  24. time.Sleep(time.Millisecond * 300)
  25. os.Exit(0)
  26. }
  27. func WithService(f func(s *Service)) func() {
  28. return func() {
  29. f(svr)
  30. }
  31. }