You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/zrpc/internal/serverinterceptors/breakerinterceptor_test.go

40 lines
1.1 KiB
Go

3 years ago
package serverinterceptors
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/breaker"
3 years ago
"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 {
3 years ago
return status.New(codes.DeadlineExceeded, "any").Err()
})
assert.NotNil(t, err)
}
func TestUnaryBreakerInterceptor(t *testing.T) {
_, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
3 years ago
FullMethod: "any",
}, func(_ context.Context, _ any) (any, error) {
3 years ago
return nil, status.New(codes.DeadlineExceeded, "any").Err()
})
assert.NotNil(t, err)
}
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)
}