12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package debug_test
- import (
- "io/ioutil"
- "kpt-tmr-group/dep"
- "kpt-tmr-group/http/middleware"
- "kpt-tmr-group/http/route"
- "kpt-tmr-group/module/backend"
- kptservicemock "kpt-tmr-group/module/backend/mock"
- "kpt-tmr-group/test/mock"
- "os"
- "testing"
- "go.uber.org/dig"
- "github.com/gin-gonic/gin"
- "github.com/golang/mock/gomock"
- )
- func TestMain(m *testing.M) {
- gin.SetMode(gin.ReleaseMode)
- gin.DefaultWriter = ioutil.Discard
- os.Exit(m.Run())
- }
- type Mock struct {
- dig.In
- KptService *kptservicemock.MockKptService
- }
- func fakeServer(t *testing.T) (*gin.Engine, *gomock.Controller, *Mock) {
- ctrl := gomock.NewController(t)
- var currMock *Mock
- mock.GetMock(ctrl, func(entry Mock) { currMock = &entry })
- g := gin.New()
- route.HTTPServerRoute(func(engine *gin.Engine) {
- engine.Use(middleware.WithDependency(&dep.HttpDependency{
- StoreEventHub: backend.Hub{
- OpsService: currMock.KptService,
- },
- }))
- })(g)
- return g, ctrl, currMock
- }
|