breakerinterceptor_test.go 796 B

123456789101112131415161718192021222324252627282930
  1. package serverinterceptors
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "google.golang.org/grpc"
  7. "google.golang.org/grpc/codes"
  8. "google.golang.org/grpc/status"
  9. )
  10. func TestStreamBreakerInterceptor(t *testing.T) {
  11. err := StreamBreakerInterceptor(nil, nil, &grpc.StreamServerInfo{
  12. FullMethod: "any",
  13. }, func(
  14. srv interface{}, stream grpc.ServerStream) error {
  15. return status.New(codes.DeadlineExceeded, "any").Err()
  16. })
  17. assert.NotNil(t, err)
  18. }
  19. func TestUnaryBreakerInterceptor(t *testing.T) {
  20. _, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
  21. FullMethod: "any",
  22. }, func(ctx context.Context, req interface{}) (interface{}, error) {
  23. return nil, status.New(codes.DeadlineExceeded, "any").Err()
  24. })
  25. assert.NotNil(t, err)
  26. }