statinterceptor_test.go 842 B

1234567891011121314151617181920212223242526272829303132
  1. package serverinterceptors
  2. import (
  3. "context"
  4. "testing"
  5. "git.i2edu.net/i2/go-zero/core/stat"
  6. "github.com/stretchr/testify/assert"
  7. "google.golang.org/grpc"
  8. )
  9. func TestUnaryStatInterceptor(t *testing.T) {
  10. metrics := stat.NewMetrics("mock")
  11. interceptor := UnaryStatInterceptor(metrics)
  12. _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
  13. FullMethod: "/",
  14. }, func(ctx context.Context, req interface{}) (interface{}, error) {
  15. return nil, nil
  16. })
  17. assert.Nil(t, err)
  18. }
  19. func TestUnaryStatInterceptor_crash(t *testing.T) {
  20. metrics := stat.NewMetrics("mock")
  21. interceptor := UnaryStatInterceptor(metrics)
  22. _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
  23. FullMethod: "/",
  24. }, func(ctx context.Context, req interface{}) (interface{}, error) {
  25. panic("error")
  26. })
  27. assert.NotNil(t, err)
  28. }