|
|
@ -24,13 +24,82 @@ func TestDurationInterceptor(t *testing.T) {
|
|
|
|
err: errors.New("mock"),
|
|
|
|
err: errors.New("mock"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
cc := new(grpc.ClientConn)
|
|
|
|
|
|
|
|
err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
|
|
|
|
|
|
|
|
func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn,
|
|
|
|
|
|
|
|
opts ...grpc.CallOption) error {
|
|
|
|
|
|
|
|
return test.err
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, test.err, err)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DontLogContentForMethod("/foo")
|
|
|
|
DontLogContentForMethod("/foo")
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
|
|
|
notLoggingContentMethods.Delete("/foo")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
cc := new(grpc.ClientConn)
|
|
|
|
|
|
|
|
err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
|
|
|
|
|
|
|
|
func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn,
|
|
|
|
|
|
|
|
opts ...grpc.CallOption) error {
|
|
|
|
|
|
|
|
return test.err
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, test.err, err)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestDurationInterceptorWithSlowThreshold(t *testing.T) {
|
|
|
|
|
|
|
|
SetSlowThreshold(time.Microsecond)
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
|
|
|
SetSlowThreshold(defaultSlowThreshold)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
err error
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "nil",
|
|
|
|
|
|
|
|
err: nil,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "with error",
|
|
|
|
|
|
|
|
err: errors.New("mock"),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
cc := new(grpc.ClientConn)
|
|
|
|
|
|
|
|
err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
|
|
|
|
|
|
|
|
func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn,
|
|
|
|
|
|
|
|
opts ...grpc.CallOption) error {
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 10)
|
|
|
|
|
|
|
|
return test.err
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, test.err, err)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DontLogContentForMethod("/foo")
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
|
|
|
notLoggingContentMethods.Delete("/foo")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
cc := new(grpc.ClientConn)
|
|
|
|
cc := new(grpc.ClientConn)
|
|
|
|
err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
|
|
|
|
err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
|
|
|
|
func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn,
|
|
|
|
func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn,
|
|
|
|
opts ...grpc.CallOption) error {
|
|
|
|
opts ...grpc.CallOption) error {
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 10)
|
|
|
|
return test.err
|
|
|
|
return test.err
|
|
|
|
})
|
|
|
|
})
|
|
|
|
assert.Equal(t, test.err, err)
|
|
|
|
assert.Equal(t, test.err, err)
|
|
|
|