prometheusinterceptor_test.go 875 B

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