MSP-4558 replace redis cli with isp-lock-service

This commit is contained in:
Пучков Андрей Павлович committed 2025-07-01 14:19:12 +03:00
1 parent 6491e79afd
commit e7bfd34e9e
14 files changed
+152 -234

No files matched your search

+16 -35
View File
@@ -15,9 +15,8 @@ import (
"isp-gate-service/domain"
"isp-gate-service/routes"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/require"
etp "github.com/txix-open/etp/v3"
"github.com/txix-open/etp/v3"
"github.com/txix-open/etp/v3/msg"
"github.com/txix-open/isp-kit/cluster"
"github.com/txix-open/isp-kit/http/httpcli"
@@ -49,7 +48,7 @@ type HappyPathTestSuite struct {
func (s *HappyPathTestSuite) TestGrpcProxy() {
test, require := test.New(s.T())
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
config, systemCli, adminCli := s.commonDependencies(test)
requestId := requestid.Next()
targetService, targetCli := grpct.NewMock(test)
@@ -86,7 +85,7 @@ func (s *HappyPathTestSuite) TestGrpcProxy() {
}})
require.NoError(err)
locator := assembly.NewLocator(logger, targetClients, nil, routes, systemCli, adminCli)
locator := assembly.NewLocator(logger, targetClients, nil, routes, systemCli, adminCli, nil)
locations := []conf.Location{{
SkipAuth: false,
@@ -94,7 +93,7 @@ func (s *HappyPathTestSuite) TestGrpcProxy() {
Protocol: "grpc",
TargetModule: "target",
}}
handler, err := locator.Handler(config, locations, redisCli)
handler, err := locator.Handler(config, locations)
require.NoError(err)
srv := httptest.NewServer(handler)
@@ -115,7 +114,7 @@ func (s *HappyPathTestSuite) TestGrpcProxy() {
func (s *HappyPathTestSuite) TestHttpProxy() {
test, require := test.New(s.T())
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
config, systemCli, adminCli := s.commonDependencies(test)
requestId := requestid.Next()
targetService := httpt.NewMock(test)
@@ -136,14 +135,14 @@ func (s *HappyPathTestSuite) TestHttpProxy() {
}})
require.NoError(err)
locator := assembly.NewLocator(test.Logger(), nil, targetClients, routes, systemCli, adminCli)
locator := assembly.NewLocator(test.Logger(), nil, targetClients, routes, systemCli, adminCli, nil)
locations := []conf.Location{{
SkipAuth: false,
PathPrefix: "/api",
Protocol: "http",
TargetModule: "target",
}}
handler, err := locator.Handler(config, locations, redisCli)
handler, err := locator.Handler(config, locations)
require.NoError(err)
srv := httptest.NewServer(handler)
@@ -164,7 +163,7 @@ func (s *HappyPathTestSuite) TestHttpProxy() {
func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
test, require := test.New(s.T())
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
config, systemCli, adminCli := s.commonDependencies(test)
requestId := requestid.Next()
wsServer := etp.NewServer(etp.WithServerReadLimit(2048))
@@ -192,14 +191,14 @@ func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
}})
require.NoError(err)
locator := assembly.NewLocator(test.Logger(), nil, targetClients, routes, systemCli, adminCli)
locator := assembly.NewLocator(test.Logger(), nil, targetClients, routes, systemCli, adminCli, nil)
locations := []conf.Location{{
SkipAuth: false,
PathPrefix: "/ws",
Protocol: "ws",
TargetModule: "target",
}}
handler, err := locator.Handler(config, locations, redisCli)
handler, err := locator.Handler(config, locations)
require.NoError(err)
srv := httptest.NewServer(handler)
@@ -242,7 +241,7 @@ func (s wsEventHandlerMock) Handle(_ context.Context, conn *etp.Conn, event msg.
func (s *HappyPathTestSuite) TestAdminAuthorization() {
test, require := test.New(s.T())
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
config, systemCli, adminCli := s.commonDependencies(test)
targetService, targetCli := grpct.NewMock(test)
targetService.Mock("endpoint", func(ctx context.Context, authData grpc.AuthData, req request) response {
@@ -252,7 +251,7 @@ func (s *HappyPathTestSuite) TestAdminAuthorization() {
logger, err := log.New(log.WithLevel(log.DebugLevel))
require.NoError(err)
routes := routes.NewRoutes()
locator := assembly.NewLocator(logger, targetClients, nil, routes, systemCli, adminCli)
locator := assembly.NewLocator(logger, targetClients, nil, routes, systemCli, adminCli, nil)
locations := []conf.Location{{
SkipAuth: false,
@@ -260,7 +259,7 @@ func (s *HappyPathTestSuite) TestAdminAuthorization() {
Protocol: "grpc",
TargetModule: "target",
}}
handler, err := locator.Handler(config, locations, redisCli)
handler, err := locator.Handler(config, locations)
require.NoError(err)
err = routes.ReceiveRoutes(context.Background(), cluster.RoutingConfig{{
@@ -304,27 +303,9 @@ func (s *HappyPathTestSuite) TestAdminAuthorization() {
}
// nolint:ireturn
func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, redis.UniversalClient, *client.Client, *client.Client) {
require := test.Assert()
redisCli := NewRedis(test)
ctx := context.Background()
s.T().Cleanup(func() {
_, err := redisCli.Pipelined(ctx, func(p redis.Pipeliner) error {
p.Select(ctx, 0)
p.FlushDB(ctx)
p.Select(ctx, 1)
p.FlushDB(ctx)
p.Select(ctx, 2)
p.FlushDB(ctx)
return nil
})
require.NoError(err)
})
func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, *client.Client, *client.Client) {
config := conf.Remote{
Redis: &conf.Redis{Address: redisCli.address},
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true,
SkipBodyLoggingEndpointPrefixes: []string{"endpoint"}},
Caching: conf.Caching{AuthorizationDataInSec: 1, AuthenticationDataInSec: 1},
@@ -363,7 +344,7 @@ func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, r
return domain.AdminAuthorizeResponse{Authorized: false}
})
return config, redisCli, systemCli, adminCli
return config, systemCli, adminCli
}
func TestHappyPathTestSuite(t *testing.T) {
+2 -3
View File
@@ -46,7 +46,6 @@ func main() {
})
}()
config := conf.Remote{
Redis: &conf.Redis{Address: "localhost:6379"},
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true},
Caching: conf.Caching{AuthorizationDataInSec: 15, AuthenticationDataInSec: 15},
@@ -85,14 +84,14 @@ func main() {
})
targetClients := map[string]*client.Client{"target": targetCli}
logger, _ = log.New(log.WithLevel(log.DebugLevel))
locator := assembly.NewLocator(logger, targetClients, nil, routes.NewRoutes(), systemCli, adminCli)
locator := assembly.NewLocator(logger, targetClients, nil, routes.NewRoutes(), systemCli, adminCli, nil)
locations := []conf.Location{{
SkipAuth: false,
PathPrefix: "/api",
Protocol: "grpc",
TargetModule: "target",
}}
handler, _ := locator.Handler(config, locations, redisCli)
handler, _ := locator.Handler(config, locations)
srv := &http.Server{
Addr: "localhost:8000",
-25
View File
@@ -1,25 +0,0 @@
package tests
import (
"fmt"
"github.com/redis/go-redis/v9"
"github.com/txix-open/isp-kit/test"
)
type Redis struct {
address string
redis.UniversalClient
}
func NewRedis(test *test.Test) Redis {
redisHost := test.Config().Optional().String("REDIS_HOST", "localhost")
redisPort := test.Config().Optional().String("REDIS_PORT", "6379")
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
cli := redis.NewClient(&redis.Options{Addr: addr})
return Redis{UniversalClient: cli, address: addr}
}
func (r Redis) Address() string {
return r.address
}