prometheusinterceptor_test.go 819 B

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