github.com/lingyao2333/mo-zero@v1.4.1/zrpc/internal/serverinterceptors/prometheusinterceptor_test.go (about)

     1  package serverinterceptors
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/lingyao2333/mo-zero/core/prometheus"
     8  	"github.com/stretchr/testify/assert"
     9  	"google.golang.org/grpc"
    10  )
    11  
    12  func TestUnaryPromMetricInterceptor_Disabled(t *testing.T) {
    13  	_, err := UnaryPrometheusInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
    14  		FullMethod: "/",
    15  	}, func(ctx context.Context, req interface{}) (interface{}, error) {
    16  		return nil, nil
    17  	})
    18  	assert.Nil(t, err)
    19  }
    20  
    21  func TestUnaryPromMetricInterceptor_Enabled(t *testing.T) {
    22  	prometheus.StartAgent(prometheus.Config{
    23  		Host: "localhost",
    24  		Path: "/",
    25  	})
    26  	_, err := UnaryPrometheusInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
    27  		FullMethod: "/",
    28  	}, func(ctx context.Context, req interface{}) (interface{}, error) {
    29  		return nil, nil
    30  	})
    31  	assert.Nil(t, err)
    32  }