x_suite_test.go 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package backend
  2. import (
  3. "context"
  4. "kpt-tmr-group/config"
  5. "kpt-tmr-group/store/kptstore"
  6. "kpt-tmr-group/test/mock"
  7. "golang.org/x/sync/errgroup"
  8. "github.com/golang/mock/gomock"
  9. "github.com/stretchr/testify/suite"
  10. "go.uber.org/dig"
  11. )
  12. var dbName = "kpt_tmr_group_test"
  13. type Suite struct {
  14. suite.Suite
  15. ctx context.Context
  16. cfg *config.AppConfig
  17. db *kptstore.DB
  18. ctrl *gomock.Controller
  19. m Mock
  20. storeEntry *StoreEntry
  21. }
  22. type Mock struct {
  23. dig.In
  24. }
  25. func (s *Suite) SetupSuite() {
  26. s.cfg = config.Options()
  27. }
  28. func (s *Suite) SetupTest() {
  29. s.ctx = context.Background()
  30. s.ctrl = gomock.NewController(s.T())
  31. mock.GetMock(s.ctrl, func(m Mock) { s.m = m })
  32. s.storeEntry = NewStoreEntry(s.cfg, s.db)
  33. }
  34. func (s *Suite) prepareDB() {
  35. s.cfg = config.Options()
  36. g, _ := errgroup.WithContext(context.Background())
  37. g.Go(func() error { // todo 连接数据库
  38. return nil
  39. })
  40. if err := g.Wait(); err != nil {
  41. panic(err)
  42. }
  43. }