chore: refactor gateway (#3157)
This commit is contained in:
@@ -44,10 +44,12 @@ func dialer() func(context.Context, string) (net.Conn, error) {
|
||||
func TestMustNewServer(t *testing.T) {
|
||||
var c GatewayConf
|
||||
assert.NoError(t, conf.FillDefault(&c))
|
||||
// avoid popup alert on macos for asking permissions
|
||||
c.DevServer.Host = "localhost"
|
||||
c.Host = "localhost"
|
||||
c.Port = 18881
|
||||
|
||||
s := MustNewServer(c)
|
||||
|
||||
s.upstreams = []*upstream{
|
||||
{
|
||||
Upstream: Upstream{
|
||||
@@ -59,22 +61,20 @@ func TestMustNewServer(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
client: zrpc.MustNewClient(zrpc.RpcClientConf{
|
||||
Endpoints: []string{"foo"},
|
||||
Timeout: 1000,
|
||||
Middlewares: zrpc.ClientMiddlewaresConf{
|
||||
Trace: true,
|
||||
Duration: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
Timeout: true,
|
||||
client: zrpc.MustNewClient(
|
||||
zrpc.RpcClientConf{
|
||||
Endpoints: []string{"foo"},
|
||||
Timeout: 1000,
|
||||
Middlewares: zrpc.ClientMiddlewaresConf{
|
||||
Trace: true,
|
||||
Duration: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
Timeout: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
zrpc.WithDialOption(grpc.WithContextDialer(dialer())),
|
||||
zrpc.WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply any,
|
||||
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
})),
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -83,13 +83,11 @@ func TestMustNewServer(t *testing.T) {
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
resp, err := httpc.Do(ctx, http.MethodGet, "http://localhost:18881/deposit/100", nil)
|
||||
resp, err := httpc.Do(context.Background(), http.MethodGet, "http://localhost:18881/deposit/100", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
resp, err = httpc.Do(ctx, http.MethodGet, "http://localhost:18881/deposit_fail/100", nil)
|
||||
resp, err = httpc.Do(context.Background(), http.MethodGet, "http://localhost:18881/deposit_fail/100", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user