You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/zrpc/internal/clientinterceptors/prometheusinterceptor_test.go

51 lines
970 B
Go

4 years ago
package clientinterceptors
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/prometheus"
4 years ago
"google.golang.org/grpc"
)
func TestPromMetricInterceptor(t *testing.T) {
tests := []struct {
name string
enable bool
err error
4 years ago
}{
{
name: "nil",
enable: true,
err: nil,
4 years ago
},
{
name: "with error",
enable: true,
err: errors.New("mock"),
},
{
name: "disabled",
4 years ago
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.enable {
prometheus.StartAgent(prometheus.Config{
Host: "localhost",
Path: "/",
})
}
4 years ago
cc := new(grpc.ClientConn)
err := PrometheusInterceptor(context.Background(), "/foo", nil, nil, cc,
4 years ago
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)
})
}
}