feat: add MustNewRedis (#2824)
* feat: add MustNewRedis * feat: add MustNewRedis * feat: add MustNewRedis * x * x * fix ut * x * x * x * x * x
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/load"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stat"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/zrpc/internal"
|
||||
"github.com/zeromicro/go-zero/zrpc/internal/auth"
|
||||
"github.com/zeromicro/go-zero/zrpc/internal/serverinterceptors"
|
||||
@@ -120,7 +121,12 @@ func setupInterceptors(server internal.Server, c RpcServerConf, metrics *stat.Me
|
||||
}
|
||||
|
||||
if c.Auth {
|
||||
authenticator, err := auth.NewAuthenticator(c.Redis.NewRedis(), c.Redis.Key, c.StrictControl)
|
||||
rds, err := redis.NewRedis(c.Redis.RedisConf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authenticator, err := auth.NewAuthenticator(rds, c.Redis.Key, c.StrictControl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/discov"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -16,12 +17,16 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_setupInterceptors(t *testing.T) {
|
||||
rds, err := miniredis.Run()
|
||||
assert.NoError(t, err)
|
||||
defer rds.Close()
|
||||
|
||||
server := new(mockedServer)
|
||||
err := setupInterceptors(server, RpcServerConf{
|
||||
conf := RpcServerConf{
|
||||
Auth: true,
|
||||
Redis: redis.RedisKeyConf{
|
||||
RedisConf: redis.RedisConf{
|
||||
Host: "any",
|
||||
Host: rds.Addr(),
|
||||
Type: redis.NodeType,
|
||||
},
|
||||
Key: "foo",
|
||||
@@ -35,10 +40,15 @@ func TestServer_setupInterceptors(t *testing.T) {
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
}, new(stat.Metrics))
|
||||
}
|
||||
err = setupInterceptors(server, conf, new(stat.Metrics))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(server.unaryInterceptors))
|
||||
assert.Equal(t, 1, len(server.streamInterceptors))
|
||||
|
||||
rds.SetError("mock error")
|
||||
err = setupInterceptors(server, conf, new(stat.Metrics))
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user