x_main_test.go 956 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package debug_test
  2. import (
  3. "io/ioutil"
  4. "kpt-tmr-group/dep"
  5. "kpt-tmr-group/http/middleware"
  6. "kpt-tmr-group/http/route"
  7. "kpt-tmr-group/module/backend"
  8. kptservicemock "kpt-tmr-group/module/backend/mock"
  9. "kpt-tmr-group/test/mock"
  10. "os"
  11. "testing"
  12. "go.uber.org/dig"
  13. "github.com/gin-gonic/gin"
  14. "github.com/golang/mock/gomock"
  15. )
  16. func TestMain(m *testing.M) {
  17. gin.SetMode(gin.ReleaseMode)
  18. gin.DefaultWriter = ioutil.Discard
  19. os.Exit(m.Run())
  20. }
  21. type Mock struct {
  22. dig.In
  23. KptService *kptservicemock.MockKptService
  24. }
  25. func fakeServer(t *testing.T) (*gin.Engine, *gomock.Controller, *Mock) {
  26. ctrl := gomock.NewController(t)
  27. var currMock *Mock
  28. mock.GetMock(ctrl, func(entry Mock) { currMock = &entry })
  29. g := gin.New()
  30. route.HTTPServerRoute(func(engine *gin.Engine) {
  31. engine.Use(middleware.WithDependency(&dep.HttpDependency{
  32. StoreEventHub: backend.Hub{
  33. OpsService: currMock.KptService,
  34. },
  35. }))
  36. })(g)
  37. return g, ctrl, currMock
  38. }