Files
go-zero/zrpc/internal/serverinterceptors/breakerinterceptor_test.go

40 lines
1.1 KiB
Go
Raw Normal View History

2021-08-04 18:45:05 +08:00
package serverinterceptors
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
2024-02-20 10:11:43 +08:00
"github.com/zeromicro/go-zero/core/breaker"
2021-08-04 18:45:05 +08:00
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestStreamBreakerInterceptor(t *testing.T) {
err := StreamBreakerInterceptor(nil, nil, &grpc.StreamServerInfo{
FullMethod: "any",
}, func(_ any, _ grpc.ServerStream) error {
2021-08-04 18:45:05 +08:00
return status.New(codes.DeadlineExceeded, "any").Err()
})
assert.NotNil(t, err)
}
func TestUnaryBreakerInterceptor(t *testing.T) {
_, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
2021-08-04 18:45:05 +08:00
FullMethod: "any",
}, func(_ context.Context, _ any) (any, error) {
2021-08-04 18:45:05 +08:00
return nil, status.New(codes.DeadlineExceeded, "any").Err()
})
assert.NotNil(t, err)
}
2024-02-20 10:11:43 +08:00
func TestUnaryBreakerInterceptor_Unavailable(t *testing.T) {
_, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
FullMethod: "any",
}, func(_ context.Context, _ any) (any, error) {
return nil, breaker.ErrServiceUnavailable
})
assert.NotNil(t, err)
}