1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package clientinterceptors
- import (
- "context"
- "errors"
- "testing"
- "git.i2edu.net/i2/go-zero/core/prometheus"
- "github.com/stretchr/testify/assert"
- "google.golang.org/grpc"
- )
- func TestPromMetricInterceptor(t *testing.T) {
- tests := []struct {
- name string
- enable bool
- err error
- }{
- {
- name: "nil",
- enable: true,
- err: nil,
- },
- {
- name: "with error",
- enable: true,
- err: errors.New("mock"),
- },
- {
- name: "disabled",
- },
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- if test.enable {
- prometheus.StartAgent(prometheus.Config{
- Host: "localhost",
- Path: "/",
- })
- }
- cc := new(grpc.ClientConn)
- err := PrometheusInterceptor(context.Background(), "/foo", nil, nil, cc,
- func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
- opts ...grpc.CallOption) error {
- return test.err
- })
- assert.Equal(t, test.err, err)
- })
- }
- }
|