breakerinterceptor_test.go 782 B

1234567891011121314151617181920212223242526272829
  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(_ interface{}, _ grpc.ServerStream) error {
  14. return status.New(codes.DeadlineExceeded, "any").Err()
  15. })
  16. assert.NotNil(t, err)
  17. }
  18. func TestUnaryBreakerInterceptor(t *testing.T) {
  19. _, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
  20. FullMethod: "any",
  21. }, func(_ context.Context, _ interface{}) (interface{}, error) {
  22. return nil, status.New(codes.DeadlineExceeded, "any").Err()
  23. })
  24. assert.NotNil(t, err)
  25. }