|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/alicebob/miniredis/v2"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zeromicro/go-zero/core/discov"
|
|
|
|
"github.com/zeromicro/go-zero/core/discov"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
@ -16,12 +17,16 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestServer_setupInterceptors(t *testing.T) {
|
|
|
|
func TestServer_setupInterceptors(t *testing.T) {
|
|
|
|
|
|
|
|
rds, err := miniredis.Run()
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
defer rds.Close()
|
|
|
|
|
|
|
|
|
|
|
|
server := new(mockedServer)
|
|
|
|
server := new(mockedServer)
|
|
|
|
err := setupInterceptors(server, RpcServerConf{
|
|
|
|
conf := RpcServerConf{
|
|
|
|
Auth: true,
|
|
|
|
Auth: true,
|
|
|
|
Redis: redis.RedisKeyConf{
|
|
|
|
Redis: redis.RedisKeyConf{
|
|
|
|
RedisConf: redis.RedisConf{
|
|
|
|
RedisConf: redis.RedisConf{
|
|
|
|
Host: "any",
|
|
|
|
Host: rds.Addr(),
|
|
|
|
Type: redis.NodeType,
|
|
|
|
Type: redis.NodeType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Key: "foo",
|
|
|
|
Key: "foo",
|
|
|
@ -35,10 +40,15 @@ func TestServer_setupInterceptors(t *testing.T) {
|
|
|
|
Prometheus: true,
|
|
|
|
Prometheus: true,
|
|
|
|
Breaker: true,
|
|
|
|
Breaker: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, new(stat.Metrics))
|
|
|
|
}
|
|
|
|
|
|
|
|
err = setupInterceptors(server, conf, new(stat.Metrics))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, 3, len(server.unaryInterceptors))
|
|
|
|
assert.Equal(t, 3, len(server.unaryInterceptors))
|
|
|
|
assert.Equal(t, 1, len(server.streamInterceptors))
|
|
|
|
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) {
|
|
|
|
func TestServer(t *testing.T) {
|
|
|
|