12345678910111213141516171819202122232425262728293031323334 |
- package serverinterceptors
- import (
- "context"
- "testing"
- "git.i2edu.net/i2/go-zero/core/prometheus"
- "github.com/stretchr/testify/assert"
- "google.golang.org/grpc"
- )
- func TestUnaryPromMetricInterceptor_Disabled(t *testing.T) {
- interceptor := UnaryPrometheusInterceptor()
- _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
- FullMethod: "/",
- }, func(ctx context.Context, req interface{}) (interface{}, error) {
- return nil, nil
- })
- assert.Nil(t, err)
- }
- func TestUnaryPromMetricInterceptor_Enabled(t *testing.T) {
- prometheus.StartAgent(prometheus.Config{
- Host: "localhost",
- Path: "/",
- })
- interceptor := UnaryPrometheusInterceptor()
- _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
- FullMethod: "/",
- }, func(ctx context.Context, req interface{}) (interface{}, error) {
- return nil, nil
- })
- assert.Nil(t, err)
- }
|