1234567891011121314151617181920212223242526272829303132 |
- package serverinterceptors
- import (
- "context"
- "testing"
- "git.i2edu.net/i2/go-zero/core/stat"
- "github.com/stretchr/testify/assert"
- "google.golang.org/grpc"
- )
- func TestUnaryStatInterceptor(t *testing.T) {
- metrics := stat.NewMetrics("mock")
- interceptor := UnaryStatInterceptor(metrics)
- _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
- FullMethod: "/",
- }, func(ctx context.Context, req interface{}) (interface{}, error) {
- return nil, nil
- })
- assert.Nil(t, err)
- }
- func TestUnaryStatInterceptor_crash(t *testing.T) {
- metrics := stat.NewMetrics("mock")
- interceptor := UnaryStatInterceptor(metrics)
- _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
- FullMethod: "/",
- }, func(ctx context.Context, req interface{}) (interface{}, error) {
- panic("error")
- })
- assert.NotNil(t, err)
- }
|